| David Tolnay | fedc63b | 2021-03-27 00:19:13 -0400 | [diff] [blame^] | 1 | use crate::syntax::instantiate::NamedImplKey; |
| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 2 | use crate::syntax::{Lifetimes, NamedType, Pair, Types}; |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 3 | use proc_macro2::Ident; |
| 4 | |
| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 5 | #[derive(Copy, Clone)] |
| 6 | pub struct Resolution<'a> { |
| 7 | pub name: &'a Pair, |
| 8 | pub generics: &'a Lifetimes, |
| 9 | } |
| 10 | |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 11 | impl<'a> Types<'a> { |
| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 12 | pub fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> { |
| 13 | *self |
| 14 | .resolutions |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 15 | .get(ident.ident()) |
| 16 | .expect("Unable to resolve type") |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | pub trait UnresolvedName { |
| 21 | fn ident(&self) -> &Ident; |
| 22 | } |
| 23 | |
| 24 | impl UnresolvedName for Ident { |
| 25 | fn ident(&self) -> &Ident { |
| 26 | self |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | impl UnresolvedName for NamedType { |
| 31 | fn ident(&self) -> &Ident { |
| 32 | &self.rust |
| 33 | } |
| 34 | } |
| David Tolnay | fedc63b | 2021-03-27 00:19:13 -0400 | [diff] [blame^] | 35 | |
| 36 | impl<'a> UnresolvedName for NamedImplKey<'a> { |
| 37 | fn ident(&self) -> &Ident { |
| 38 | self.rust |
| 39 | } |
| 40 | } |