1use crate::syntax::instantiate::NamedImplKey; 2use crate::syntax::{Lifetimes, NamedType, Pair, Types}; 3use proc_macro2::Ident; 4 5#[derive(Copy, Clone)] 6pub struct Resolution<'a> { 7 pub name: &'a Pair, 8 pub generics: &'a Lifetimes, 9} 10 11impl<'a> Types<'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 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 26pub trait UnresolvedName { 27 fn ident(&self) -> &Ident; 28} 29 30impl UnresolvedName for Ident { 31 fn ident(&self) -> &Ident { 32 self 33 } 34} 35 36impl UnresolvedName for NamedType { 37 fn ident(&self) -> &Ident { 38 &self.rust 39 } 40} 41 42impl<'a> UnresolvedName for NamedImplKey<'a> { 43 fn ident(&self) -> &Ident { 44 self.rust 45 } 46} 47