diff options
author | Dmitry <[email protected]> | 2020-08-09 14:35:51 +0100 |
---|---|---|
committer | Dmitry <[email protected]> | 2020-08-09 14:39:32 +0100 |
commit | 8068302fefc75440b823f4bf1731a5f347d7c767 (patch) | |
tree | 251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_hir/src/semantics | |
parent | 1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff) | |
parent | 8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_hir/src/semantics')
-rw-r--r-- | crates/ra_hir/src/semantics/source_to_def.rs | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 42e5a1bdb..863e8e5ff 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs | |||
@@ -65,57 +65,48 @@ impl SourceToDefCtx<'_, '_> { | |||
65 | Some(ModuleId { krate: parent_module.krate, local_id: child_id }) | 65 | Some(ModuleId { krate: parent_module.krate, local_id: child_id }) |
66 | } | 66 | } |
67 | 67 | ||
68 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> { | 68 | pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { |
69 | self.to_def(src, keys::TRAIT) | 69 | self.to_def(src, keys::TRAIT) |
70 | } | 70 | } |
71 | pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> { | 71 | pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> { |
72 | self.to_def(src, keys::IMPL) | 72 | self.to_def(src, keys::IMPL) |
73 | } | 73 | } |
74 | pub(super) fn fn_to_def(&mut self, src: InFile<ast::FnDef>) -> Option<FunctionId> { | 74 | pub(super) fn fn_to_def(&mut self, src: InFile<ast::Fn>) -> Option<FunctionId> { |
75 | self.to_def(src, keys::FUNCTION) | 75 | self.to_def(src, keys::FUNCTION) |
76 | } | 76 | } |
77 | pub(super) fn struct_to_def(&mut self, src: InFile<ast::StructDef>) -> Option<StructId> { | 77 | pub(super) fn struct_to_def(&mut self, src: InFile<ast::Struct>) -> Option<StructId> { |
78 | self.to_def(src, keys::STRUCT) | 78 | self.to_def(src, keys::STRUCT) |
79 | } | 79 | } |
80 | pub(super) fn enum_to_def(&mut self, src: InFile<ast::EnumDef>) -> Option<EnumId> { | 80 | pub(super) fn enum_to_def(&mut self, src: InFile<ast::Enum>) -> Option<EnumId> { |
81 | self.to_def(src, keys::ENUM) | 81 | self.to_def(src, keys::ENUM) |
82 | } | 82 | } |
83 | pub(super) fn union_to_def(&mut self, src: InFile<ast::UnionDef>) -> Option<UnionId> { | 83 | pub(super) fn union_to_def(&mut self, src: InFile<ast::Union>) -> Option<UnionId> { |
84 | self.to_def(src, keys::UNION) | 84 | self.to_def(src, keys::UNION) |
85 | } | 85 | } |
86 | pub(super) fn static_to_def(&mut self, src: InFile<ast::StaticDef>) -> Option<StaticId> { | 86 | pub(super) fn static_to_def(&mut self, src: InFile<ast::Static>) -> Option<StaticId> { |
87 | self.to_def(src, keys::STATIC) | 87 | self.to_def(src, keys::STATIC) |
88 | } | 88 | } |
89 | pub(super) fn const_to_def(&mut self, src: InFile<ast::ConstDef>) -> Option<ConstId> { | 89 | pub(super) fn const_to_def(&mut self, src: InFile<ast::Const>) -> Option<ConstId> { |
90 | self.to_def(src, keys::CONST) | 90 | self.to_def(src, keys::CONST) |
91 | } | 91 | } |
92 | pub(super) fn type_alias_to_def( | 92 | pub(super) fn type_alias_to_def(&mut self, src: InFile<ast::TypeAlias>) -> Option<TypeAliasId> { |
93 | &mut self, | ||
94 | src: InFile<ast::TypeAliasDef>, | ||
95 | ) -> Option<TypeAliasId> { | ||
96 | self.to_def(src, keys::TYPE_ALIAS) | 93 | self.to_def(src, keys::TYPE_ALIAS) |
97 | } | 94 | } |
98 | pub(super) fn record_field_to_def( | 95 | pub(super) fn record_field_to_def(&mut self, src: InFile<ast::RecordField>) -> Option<FieldId> { |
99 | &mut self, | ||
100 | src: InFile<ast::RecordFieldDef>, | ||
101 | ) -> Option<FieldId> { | ||
102 | self.to_def(src, keys::RECORD_FIELD) | 96 | self.to_def(src, keys::RECORD_FIELD) |
103 | } | 97 | } |
104 | pub(super) fn tuple_field_to_def( | 98 | pub(super) fn tuple_field_to_def(&mut self, src: InFile<ast::TupleField>) -> Option<FieldId> { |
105 | &mut self, | ||
106 | src: InFile<ast::TupleFieldDef>, | ||
107 | ) -> Option<FieldId> { | ||
108 | self.to_def(src, keys::TUPLE_FIELD) | 99 | self.to_def(src, keys::TUPLE_FIELD) |
109 | } | 100 | } |
110 | pub(super) fn enum_variant_to_def( | 101 | pub(super) fn enum_variant_to_def( |
111 | &mut self, | 102 | &mut self, |
112 | src: InFile<ast::EnumVariant>, | 103 | src: InFile<ast::Variant>, |
113 | ) -> Option<EnumVariantId> { | 104 | ) -> Option<EnumVariantId> { |
114 | self.to_def(src, keys::ENUM_VARIANT) | 105 | self.to_def(src, keys::VARIANT) |
115 | } | 106 | } |
116 | pub(super) fn bind_pat_to_def( | 107 | pub(super) fn bind_pat_to_def( |
117 | &mut self, | 108 | &mut self, |
118 | src: InFile<ast::BindPat>, | 109 | src: InFile<ast::IdentPat>, |
119 | ) -> Option<(DefWithBodyId, PatId)> { | 110 | ) -> Option<(DefWithBodyId, PatId)> { |
120 | let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?; | 111 | let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?; |
121 | let (_body, source_map) = self.db.body_with_source_map(container); | 112 | let (_body, source_map) = self.db.body_with_source_map(container); |
@@ -163,39 +154,39 @@ impl SourceToDefCtx<'_, '_> { | |||
163 | let def = self.module_to_def(container.with_value(it))?; | 154 | let def = self.module_to_def(container.with_value(it))?; |
164 | def.into() | 155 | def.into() |
165 | }, | 156 | }, |
166 | ast::TraitDef(it) => { | 157 | ast::Trait(it) => { |
167 | let def = self.trait_to_def(container.with_value(it))?; | 158 | let def = self.trait_to_def(container.with_value(it))?; |
168 | def.into() | 159 | def.into() |
169 | }, | 160 | }, |
170 | ast::ImplDef(it) => { | 161 | ast::Impl(it) => { |
171 | let def = self.impl_to_def(container.with_value(it))?; | 162 | let def = self.impl_to_def(container.with_value(it))?; |
172 | def.into() | 163 | def.into() |
173 | }, | 164 | }, |
174 | ast::FnDef(it) => { | 165 | ast::Fn(it) => { |
175 | let def = self.fn_to_def(container.with_value(it))?; | 166 | let def = self.fn_to_def(container.with_value(it))?; |
176 | DefWithBodyId::from(def).into() | 167 | DefWithBodyId::from(def).into() |
177 | }, | 168 | }, |
178 | ast::StructDef(it) => { | 169 | ast::Struct(it) => { |
179 | let def = self.struct_to_def(container.with_value(it))?; | 170 | let def = self.struct_to_def(container.with_value(it))?; |
180 | VariantId::from(def).into() | 171 | VariantId::from(def).into() |
181 | }, | 172 | }, |
182 | ast::EnumDef(it) => { | 173 | ast::Enum(it) => { |
183 | let def = self.enum_to_def(container.with_value(it))?; | 174 | let def = self.enum_to_def(container.with_value(it))?; |
184 | def.into() | 175 | def.into() |
185 | }, | 176 | }, |
186 | ast::UnionDef(it) => { | 177 | ast::Union(it) => { |
187 | let def = self.union_to_def(container.with_value(it))?; | 178 | let def = self.union_to_def(container.with_value(it))?; |
188 | VariantId::from(def).into() | 179 | VariantId::from(def).into() |
189 | }, | 180 | }, |
190 | ast::StaticDef(it) => { | 181 | ast::Static(it) => { |
191 | let def = self.static_to_def(container.with_value(it))?; | 182 | let def = self.static_to_def(container.with_value(it))?; |
192 | DefWithBodyId::from(def).into() | 183 | DefWithBodyId::from(def).into() |
193 | }, | 184 | }, |
194 | ast::ConstDef(it) => { | 185 | ast::Const(it) => { |
195 | let def = self.const_to_def(container.with_value(it))?; | 186 | let def = self.const_to_def(container.with_value(it))?; |
196 | DefWithBodyId::from(def).into() | 187 | DefWithBodyId::from(def).into() |
197 | }, | 188 | }, |
198 | ast::TypeAliasDef(it) => { | 189 | ast::TypeAlias(it) => { |
199 | let def = self.type_alias_to_def(container.with_value(it))?; | 190 | let def = self.type_alias_to_def(container.with_value(it))?; |
200 | def.into() | 191 | def.into() |
201 | }, | 192 | }, |
@@ -213,12 +204,12 @@ impl SourceToDefCtx<'_, '_> { | |||
213 | for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { | 204 | for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { |
214 | let res: GenericDefId = match_ast! { | 205 | let res: GenericDefId = match_ast! { |
215 | match (container.value) { | 206 | match (container.value) { |
216 | ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), | 207 | ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), |
217 | ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), | 208 | ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(), |
218 | ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), | 209 | ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(), |
219 | ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), | 210 | ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(), |
220 | ast::TypeAliasDef(it) => self.type_alias_to_def(container.with_value(it))?.into(), | 211 | ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), |
221 | ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), | 212 | ast::Impl(it) => self.impl_to_def(container.with_value(it))?.into(), |
222 | _ => continue, | 213 | _ => continue, |
223 | } | 214 | } |
224 | }; | 215 | }; |
@@ -231,9 +222,9 @@ impl SourceToDefCtx<'_, '_> { | |||
231 | for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { | 222 | for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { |
232 | let res: DefWithBodyId = match_ast! { | 223 | let res: DefWithBodyId = match_ast! { |
233 | match (container.value) { | 224 | match (container.value) { |
234 | ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), | 225 | ast::Const(it) => self.const_to_def(container.with_value(it))?.into(), |
235 | ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), | 226 | ast::Static(it) => self.static_to_def(container.with_value(it))?.into(), |
236 | ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), | 227 | ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), |
237 | _ => continue, | 228 | _ => continue, |
238 | } | 229 | } |
239 | }; | 230 | }; |