diff options
Diffstat (limited to 'crates/hir_def/src/nameres/path_resolution.rs')
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index ecf75c777..f2b59172d 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -110,6 +110,7 @@ impl DefMap { | |||
110 | let mut result = ResolvePathResult::empty(ReachedFixedPoint::No); | 110 | let mut result = ResolvePathResult::empty(ReachedFixedPoint::No); |
111 | result.segment_index = Some(usize::max_value()); | 111 | result.segment_index = Some(usize::max_value()); |
112 | 112 | ||
113 | let mut arc; | ||
113 | let mut current_map = self; | 114 | let mut current_map = self; |
114 | loop { | 115 | loop { |
115 | let new = current_map.resolve_path_fp_with_macro_single( | 116 | let new = current_map.resolve_path_fp_with_macro_single( |
@@ -131,8 +132,9 @@ impl DefMap { | |||
131 | 132 | ||
132 | match ¤t_map.block { | 133 | match ¤t_map.block { |
133 | Some(block) => { | 134 | Some(block) => { |
134 | current_map = &block.parent; | 135 | original_module = block.parent.local_id; |
135 | original_module = block.parent_module; | 136 | arc = block.parent.def_map(db); |
137 | current_map = &*arc; | ||
136 | } | 138 | } |
137 | None => return result, | 139 | None => return result, |
138 | } | 140 | } |
@@ -147,12 +149,12 @@ impl DefMap { | |||
147 | path: &ModPath, | 149 | path: &ModPath, |
148 | shadow: BuiltinShadowMode, | 150 | shadow: BuiltinShadowMode, |
149 | ) -> ResolvePathResult { | 151 | ) -> ResolvePathResult { |
150 | let mut segments = path.segments.iter().enumerate(); | 152 | let mut segments = path.segments().iter().enumerate(); |
151 | let mut curr_per_ns: PerNs = match path.kind { | 153 | let mut curr_per_ns: PerNs = match path.kind { |
152 | PathKind::DollarCrate(krate) => { | 154 | PathKind::DollarCrate(krate) => { |
153 | if krate == self.krate { | 155 | if krate == self.krate { |
154 | mark::hit!(macro_dollar_crate_self); | 156 | mark::hit!(macro_dollar_crate_self); |
155 | PerNs::types(self.crate_root().into(), Visibility::Public) | 157 | PerNs::types(self.crate_root(db).into(), Visibility::Public) |
156 | } else { | 158 | } else { |
157 | let def_map = db.crate_def_map(krate); | 159 | let def_map = db.crate_def_map(krate); |
158 | let module = def_map.module_id(def_map.root); | 160 | let module = def_map.module_id(def_map.root); |
@@ -160,7 +162,7 @@ impl DefMap { | |||
160 | PerNs::types(module.into(), Visibility::Public) | 162 | PerNs::types(module.into(), Visibility::Public) |
161 | } | 163 | } |
162 | } | 164 | } |
163 | PathKind::Crate => PerNs::types(self.crate_root().into(), Visibility::Public), | 165 | PathKind::Crate => PerNs::types(self.crate_root(db).into(), Visibility::Public), |
164 | // plain import or absolute path in 2015: crate-relative with | 166 | // plain import or absolute path in 2015: crate-relative with |
165 | // fallback to extern prelude (with the simplification in | 167 | // fallback to extern prelude (with the simplification in |
166 | // rust-lang/rust#57745) | 168 | // rust-lang/rust#57745) |
@@ -188,7 +190,7 @@ impl DefMap { | |||
188 | // BuiltinShadowMode wasn't Module, then we need to try | 190 | // BuiltinShadowMode wasn't Module, then we need to try |
189 | // resolving it as a builtin. | 191 | // resolving it as a builtin. |
190 | let prefer_module = | 192 | let prefer_module = |
191 | if path.segments.len() == 1 { shadow } else { BuiltinShadowMode::Module }; | 193 | if path.segments().len() == 1 { shadow } else { BuiltinShadowMode::Module }; |
192 | 194 | ||
193 | log::debug!("resolving {:?} in module", segment); | 195 | log::debug!("resolving {:?} in module", segment); |
194 | self.resolve_name_in_module(db, original_module, &segment, prefer_module) | 196 | self.resolve_name_in_module(db, original_module, &segment, prefer_module) |
@@ -201,15 +203,15 @@ impl DefMap { | |||
201 | None => match &self.block { | 203 | None => match &self.block { |
202 | Some(block) => { | 204 | Some(block) => { |
203 | // Look up remaining path in parent `DefMap` | 205 | // Look up remaining path in parent `DefMap` |
204 | let new_path = ModPath { | 206 | let new_path = ModPath::from_segments( |
205 | kind: PathKind::Super(lvl - i), | 207 | PathKind::Super(lvl - i), |
206 | segments: path.segments.clone(), | 208 | path.segments().to_vec(), |
207 | }; | 209 | ); |
208 | log::debug!("`super` path: {} -> {} in parent map", path, new_path); | 210 | log::debug!("`super` path: {} -> {} in parent map", path, new_path); |
209 | return block.parent.resolve_path_fp_with_macro( | 211 | return block.parent.def_map(db).resolve_path_fp_with_macro( |
210 | db, | 212 | db, |
211 | mode, | 213 | mode, |
212 | block.parent_module, | 214 | block.parent.local_id, |
213 | &new_path, | 215 | &new_path, |
214 | shadow, | 216 | shadow, |
215 | ); | 217 | ); |
@@ -256,10 +258,10 @@ impl DefMap { | |||
256 | curr_per_ns = match curr { | 258 | curr_per_ns = match curr { |
257 | ModuleDefId::ModuleId(module) => { | 259 | ModuleDefId::ModuleId(module) => { |
258 | if module.krate != self.krate { | 260 | if module.krate != self.krate { |
259 | let path = ModPath { | 261 | let path = ModPath::from_segments( |
260 | segments: path.segments[i..].to_vec(), | 262 | PathKind::Super(0), |
261 | kind: PathKind::Super(0), | 263 | path.segments()[i..].iter().cloned(), |
262 | }; | 264 | ); |
263 | log::debug!("resolving {:?} in other crate", path); | 265 | log::debug!("resolving {:?} in other crate", path); |
264 | let defp_map = module.def_map(db); | 266 | let defp_map = module.def_map(db); |
265 | let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow); | 267 | let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow); |