diff options
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 8f002d2ee..ca003576a 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -52,16 +52,16 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> { | |||
52 | SourceAnalyzer::new_for_resolver(resolver, src) | 52 | SourceAnalyzer::new_for_resolver(resolver, src) |
53 | } | 53 | } |
54 | 54 | ||
55 | pub fn to_def<D, ID>(&mut self, src: InFile<ID::Ast>) -> Option<D> | 55 | pub fn to_def<D, T>(&mut self, src: InFile<T>) -> Option<D> |
56 | where | 56 | where |
57 | D: From<ID>, | 57 | D: From<T::ID>, |
58 | ID: ToId, | 58 | T: ToId, |
59 | { | 59 | { |
60 | let id: ID = self.to_id(src)?; | 60 | let id: T::ID = self.to_id(src)?; |
61 | Some(id.into()) | 61 | Some(id.into()) |
62 | } | 62 | } |
63 | 63 | ||
64 | fn to_id<D: ToId>(&mut self, src: InFile<D::Ast>) -> Option<D> { | 64 | fn to_id<T: ToId>(&mut self, src: InFile<T>) -> Option<T::ID> { |
65 | let container = self.find_container(src.as_ref().map(|it| it.syntax()))?; | 65 | let container = self.find_container(src.as_ref().map(|it| it.syntax()))?; |
66 | let db = self.db; | 66 | let db = self.db; |
67 | let dyn_map = | 67 | let dyn_map = |
@@ -73,7 +73,7 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> { | |||
73 | ChildContainer::EnumId(it) => it.child_by_source(db), | 73 | ChildContainer::EnumId(it) => it.child_by_source(db), |
74 | ChildContainer::VariantId(it) => it.child_by_source(db), | 74 | ChildContainer::VariantId(it) => it.child_by_source(db), |
75 | }); | 75 | }); |
76 | dyn_map[D::KEY].get(&src).copied() | 76 | dyn_map[T::KEY].get(&src).copied() |
77 | } | 77 | } |
78 | 78 | ||
79 | fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { | 79 | fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { |
@@ -144,16 +144,16 @@ impl_froms! { | |||
144 | VariantId, | 144 | VariantId, |
145 | } | 145 | } |
146 | 146 | ||
147 | pub trait ToId: Sized + Copy + 'static { | 147 | pub trait ToId: Sized + AstNode + 'static { |
148 | type Ast: AstNode + 'static; | 148 | type ID: Sized + Copy + 'static; |
149 | const KEY: Key<Self::Ast, Self>; | 149 | const KEY: Key<Self, Self::ID>; |
150 | } | 150 | } |
151 | 151 | ||
152 | macro_rules! to_id_impls { | 152 | macro_rules! to_id_impls { |
153 | ($(($id:ident, $ast:path, $key:path)),* ,) => {$( | 153 | ($(($id:ident, $ast:path, $key:path)),* ,) => {$( |
154 | impl ToId for $id { | 154 | impl ToId for $ast { |
155 | type Ast = $ast; | 155 | type ID = $id; |
156 | const KEY: Key<Self::Ast, Self> = $key; | 156 | const KEY: Key<Self, Self::ID> = $key; |
157 | } | 157 | } |
158 | )*} | 158 | )*} |
159 | } | 159 | } |