diff options
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 27 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 24 |
2 files changed, 16 insertions, 35 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index adfcf879a..393170b32 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -37,8 +37,8 @@ use crate::{ | |||
37 | per_ns::PerNs, | 37 | per_ns::PerNs, |
38 | visibility::{RawVisibility, Visibility}, | 38 | visibility::{RawVisibility, Visibility}, |
39 | AdtId, AsMacroCall, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, | 39 | AdtId, AsMacroCall, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, |
40 | FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, | 40 | FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, |
41 | TraitLoc, TypeAliasLoc, UnionLoc, | 41 | TypeAliasLoc, UnionLoc, |
42 | }; | 42 | }; |
43 | 43 | ||
44 | const GLOB_RECURSION_LIMIT: usize = 100; | 44 | const GLOB_RECURSION_LIMIT: usize = 100; |
@@ -56,10 +56,9 @@ pub(super) fn collect_defs( | |||
56 | for dep in &crate_graph[def_map.krate].dependencies { | 56 | for dep in &crate_graph[def_map.krate].dependencies { |
57 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 57 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
58 | let dep_def_map = db.crate_def_map(dep.crate_id); | 58 | let dep_def_map = db.crate_def_map(dep.crate_id); |
59 | def_map.extern_prelude.insert( | 59 | def_map |
60 | dep.as_name(), | 60 | .extern_prelude |
61 | ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), | 61 | .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); |
62 | ); | ||
63 | 62 | ||
64 | // look for the prelude | 63 | // look for the prelude |
65 | // If the dependency defines a prelude, we overwrite an already defined | 64 | // If the dependency defines a prelude, we overwrite an already defined |
@@ -332,11 +331,9 @@ impl DefCollector<'_> { | |||
332 | // exported in type/value namespace. This function reduces the visibility of all items | 331 | // exported in type/value namespace. This function reduces the visibility of all items |
333 | // in the crate root that aren't proc macros. | 332 | // in the crate root that aren't proc macros. |
334 | let root = self.def_map.root; | 333 | let root = self.def_map.root; |
334 | let module_id = self.def_map.module_id(root); | ||
335 | let root = &mut self.def_map.modules[root]; | 335 | let root = &mut self.def_map.modules[root]; |
336 | root.scope.censor_non_proc_macros(ModuleId { | 336 | root.scope.censor_non_proc_macros(module_id); |
337 | krate: self.def_map.krate, | ||
338 | local_id: self.def_map.root, | ||
339 | }); | ||
340 | } | 337 | } |
341 | } | 338 | } |
342 | 339 | ||
@@ -1029,8 +1026,7 @@ impl ModCollector<'_, '_> { | |||
1029 | continue; | 1026 | continue; |
1030 | } | 1027 | } |
1031 | } | 1028 | } |
1032 | let module = | 1029 | let module = self.def_collector.def_map.module_id(self.module_id); |
1033 | ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; | ||
1034 | let container = ContainerId::ModuleId(module); | 1030 | let container = ContainerId::ModuleId(module); |
1035 | 1031 | ||
1036 | let mut def = None; | 1032 | let mut def = None; |
@@ -1097,10 +1093,7 @@ impl ModCollector<'_, '_> { | |||
1097 | } | 1093 | } |
1098 | } | 1094 | } |
1099 | ModItem::Impl(imp) => { | 1095 | ModItem::Impl(imp) => { |
1100 | let module = ModuleId { | 1096 | let module = self.def_collector.def_map.module_id(self.module_id); |
1101 | krate: self.def_collector.def_map.krate, | ||
1102 | local_id: self.module_id, | ||
1103 | }; | ||
1104 | let container = ContainerId::ModuleId(module); | 1097 | let container = ContainerId::ModuleId(module); |
1105 | let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } | 1098 | let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } |
1106 | .intern(self.def_collector.db); | 1099 | .intern(self.def_collector.db); |
@@ -1343,7 +1336,7 @@ impl ModCollector<'_, '_> { | |||
1343 | modules[res].scope.define_legacy_macro(name, mac) | 1336 | modules[res].scope.define_legacy_macro(name, mac) |
1344 | } | 1337 | } |
1345 | modules[self.module_id].children.insert(name.clone(), res); | 1338 | modules[self.module_id].children.insert(name.clone(), res); |
1346 | let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; | 1339 | let module = self.def_collector.def_map.module_id(res); |
1347 | let def: ModuleDefId = module.into(); | 1340 | let def: ModuleDefId = module.into(); |
1348 | self.def_collector.def_map.modules[self.module_id].scope.define_def(def); | 1341 | self.def_collector.def_map.modules[self.module_id].scope.define_def(def); |
1349 | self.def_collector.update( | 1342 | self.def_collector.update( |
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 7b5fe24a7..c1eded5f2 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | path::{ModPath, PathKind}, | 24 | path::{ModPath, PathKind}, |
25 | per_ns::PerNs, | 25 | per_ns::PerNs, |
26 | visibility::{RawVisibility, Visibility}, | 26 | visibility::{RawVisibility, Visibility}, |
27 | AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, | 27 | AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 30 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
@@ -66,10 +66,7 @@ impl DefMap { | |||
66 | pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { | 66 | pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { |
67 | if name == &name!(self) { | 67 | if name == &name!(self) { |
68 | mark::hit!(extern_crate_self_as); | 68 | mark::hit!(extern_crate_self_as); |
69 | return PerNs::types( | 69 | return PerNs::types(self.module_id(self.root).into(), Visibility::Public); |
70 | ModuleId { krate: self.krate, local_id: self.root }.into(), | ||
71 | Visibility::Public, | ||
72 | ); | ||
73 | } | 70 | } |
74 | self.extern_prelude | 71 | self.extern_prelude |
75 | .get(name) | 72 | .get(name) |
@@ -154,21 +151,15 @@ impl DefMap { | |||
154 | PathKind::DollarCrate(krate) => { | 151 | PathKind::DollarCrate(krate) => { |
155 | if krate == self.krate { | 152 | if krate == self.krate { |
156 | mark::hit!(macro_dollar_crate_self); | 153 | mark::hit!(macro_dollar_crate_self); |
157 | PerNs::types( | 154 | PerNs::types(self.module_id(self.root).into(), Visibility::Public) |
158 | ModuleId { krate: self.krate, local_id: self.root }.into(), | ||
159 | Visibility::Public, | ||
160 | ) | ||
161 | } else { | 155 | } else { |
162 | let def_map = db.crate_def_map(krate); | 156 | let def_map = db.crate_def_map(krate); |
163 | let module = ModuleId { krate, local_id: def_map.root }; | 157 | let module = def_map.module_id(def_map.root); |
164 | mark::hit!(macro_dollar_crate_other); | 158 | mark::hit!(macro_dollar_crate_other); |
165 | PerNs::types(module.into(), Visibility::Public) | 159 | PerNs::types(module.into(), Visibility::Public) |
166 | } | 160 | } |
167 | } | 161 | } |
168 | PathKind::Crate => PerNs::types( | 162 | PathKind::Crate => PerNs::types(self.module_id(self.root).into(), Visibility::Public), |
169 | ModuleId { krate: self.krate, local_id: self.root }.into(), | ||
170 | Visibility::Public, | ||
171 | ), | ||
172 | // plain import or absolute path in 2015: crate-relative with | 163 | // plain import or absolute path in 2015: crate-relative with |
173 | // fallback to extern prelude (with the simplification in | 164 | // fallback to extern prelude (with the simplification in |
174 | // rust-lang/rust#57745) | 165 | // rust-lang/rust#57745) |
@@ -205,10 +196,7 @@ impl DefMap { | |||
205 | let m = successors(Some(original_module), |m| self.modules[*m].parent) | 196 | let m = successors(Some(original_module), |m| self.modules[*m].parent) |
206 | .nth(lvl as usize); | 197 | .nth(lvl as usize); |
207 | if let Some(local_id) = m { | 198 | if let Some(local_id) = m { |
208 | PerNs::types( | 199 | PerNs::types(self.module_id(local_id).into(), Visibility::Public) |
209 | ModuleId { krate: self.krate, local_id }.into(), | ||
210 | Visibility::Public, | ||
211 | ) | ||
212 | } else { | 200 | } else { |
213 | log::debug!("super path in root module"); | 201 | log::debug!("super path in root module"); |
214 | return ResolvePathResult::empty(ReachedFixedPoint::Yes); | 202 | return ResolvePathResult::empty(ReachedFixedPoint::Yes); |