• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::syntax::instantiate::NamedImplKey;
2 use crate::syntax::{Lifetimes, NamedType, Pair, Types};
3 use proc_macro2::Ident;
4 
5 #[derive(Copy, Clone)]
6 pub struct Resolution<'a> {
7     pub name: &'a Pair,
8     pub generics: &'a Lifetimes,
9 }
10 
11 impl<'a> Types<'a> {
resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a>12     pub fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> {
13         let ident = ident.ident();
14         match self.try_resolve(ident) {
15             Some(resolution) => resolution,
16             None => panic!("Unable to resolve type `{}`", ident),
17         }
18     }
19 
try_resolve(&self, ident: &impl UnresolvedName) -> Option<Resolution<'a>>20     pub fn try_resolve(&self, ident: &impl UnresolvedName) -> Option<Resolution<'a>> {
21         let ident = ident.ident();
22         self.resolutions.get(ident).copied()
23     }
24 }
25 
26 pub trait UnresolvedName {
ident(&self) -> &Ident27     fn ident(&self) -> &Ident;
28 }
29 
30 impl UnresolvedName for Ident {
ident(&self) -> &Ident31     fn ident(&self) -> &Ident {
32         self
33     }
34 }
35 
36 impl UnresolvedName for NamedType {
ident(&self) -> &Ident37     fn ident(&self) -> &Ident {
38         &self.rust
39     }
40 }
41 
42 impl<'a> UnresolvedName for NamedImplKey<'a> {
ident(&self) -> &Ident43     fn ident(&self) -> &Ident {
44         self.rust
45     }
46 }
47