diff options
Diffstat (limited to 'crates/hir_def/src/item_scope.rs')
-rw-r--r-- | crates/hir_def/src/item_scope.rs | 56 |
1 files changed, 7 insertions, 49 deletions
diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index ee46c3330..aafd73b60 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs | |||
@@ -9,11 +9,10 @@ use hir_expand::MacroDefKind; | |||
9 | use once_cell::sync::Lazy; | 9 | use once_cell::sync::Lazy; |
10 | use rustc_hash::{FxHashMap, FxHashSet}; | 10 | use rustc_hash::{FxHashMap, FxHashSet}; |
11 | use stdx::format_to; | 11 | use stdx::format_to; |
12 | use test_utils::mark; | ||
13 | 12 | ||
14 | use crate::{ | 13 | use crate::{ |
15 | db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, | 14 | db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ImplId, |
16 | LocalModuleId, Lookup, MacroDefId, ModuleDefId, ModuleId, TraitId, | 15 | LocalModuleId, MacroDefId, ModuleDefId, ModuleId, TraitId, |
17 | }; | 16 | }; |
18 | 17 | ||
19 | #[derive(Copy, Clone)] | 18 | #[derive(Copy, Clone)] |
@@ -169,37 +168,6 @@ impl ItemScope { | |||
169 | self.unnamed_trait_imports.insert(tr, vis); | 168 | self.unnamed_trait_imports.insert(tr, vis); |
170 | } | 169 | } |
171 | 170 | ||
172 | pub(crate) fn push_res(&mut self, name: Name, def: PerNs) -> bool { | ||
173 | let mut changed = false; | ||
174 | |||
175 | if let Some(types) = def.types { | ||
176 | self.types.entry(name.clone()).or_insert_with(|| { | ||
177 | changed = true; | ||
178 | types | ||
179 | }); | ||
180 | } | ||
181 | if let Some(values) = def.values { | ||
182 | self.values.entry(name.clone()).or_insert_with(|| { | ||
183 | changed = true; | ||
184 | values | ||
185 | }); | ||
186 | } | ||
187 | if let Some(macros) = def.macros { | ||
188 | self.macros.entry(name.clone()).or_insert_with(|| { | ||
189 | changed = true; | ||
190 | macros | ||
191 | }); | ||
192 | } | ||
193 | |||
194 | if def.is_none() { | ||
195 | if self.unresolved.insert(name) { | ||
196 | changed = true; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | changed | ||
201 | } | ||
202 | |||
203 | pub(crate) fn push_res_with_import( | 171 | pub(crate) fn push_res_with_import( |
204 | &mut self, | 172 | &mut self, |
205 | glob_imports: &mut PerNsGlobImports, | 173 | glob_imports: &mut PerNsGlobImports, |
@@ -237,7 +205,7 @@ impl ItemScope { | |||
237 | if $glob_imports.$field.contains(&$lookup) | 205 | if $glob_imports.$field.contains(&$lookup) |
238 | && matches!($def_import_type, ImportType::Named) => | 206 | && matches!($def_import_type, ImportType::Named) => |
239 | { | 207 | { |
240 | mark::hit!(import_shadowed); | 208 | cov_mark::hit!(import_shadowed); |
241 | $glob_imports.$field.remove(&$lookup); | 209 | $glob_imports.$field.remove(&$lookup); |
242 | if let Some(fld) = $def.$field { | 210 | if let Some(fld) = $def.$field { |
243 | entry.insert(fld); | 211 | entry.insert(fld); |
@@ -375,19 +343,9 @@ impl ItemInNs { | |||
375 | 343 | ||
376 | /// Returns the crate defining this item (or `None` if `self` is built-in). | 344 | /// Returns the crate defining this item (or `None` if `self` is built-in). |
377 | pub fn krate(&self, db: &dyn DefDatabase) -> Option<CrateId> { | 345 | pub fn krate(&self, db: &dyn DefDatabase) -> Option<CrateId> { |
378 | Some(match self { | 346 | match self { |
379 | ItemInNs::Types(did) | ItemInNs::Values(did) => match did { | 347 | ItemInNs::Types(did) | ItemInNs::Values(did) => did.module(db).map(|m| m.krate), |
380 | ModuleDefId::ModuleId(id) => id.krate, | 348 | ItemInNs::Macros(id) => Some(id.krate), |
381 | ModuleDefId::FunctionId(id) => id.lookup(db).module(db).krate, | 349 | } |
382 | ModuleDefId::AdtId(id) => id.module(db).krate, | ||
383 | ModuleDefId::EnumVariantId(id) => id.parent.lookup(db).container.module(db).krate, | ||
384 | ModuleDefId::ConstId(id) => id.lookup(db).container.module(db).krate, | ||
385 | ModuleDefId::StaticId(id) => id.lookup(db).container.module(db).krate, | ||
386 | ModuleDefId::TraitId(id) => id.lookup(db).container.module(db).krate, | ||
387 | ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db).krate, | ||
388 | ModuleDefId::BuiltinType(_) => return None, | ||
389 | }, | ||
390 | ItemInNs::Macros(id) => return Some(id.krate), | ||
391 | }) | ||
392 | } | 350 | } |
393 | } | 351 | } |