aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/path_resolution.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-01-25 18:15:39 +0000
committerJonas Schievink <[email protected]>2021-01-25 18:15:39 +0000
commit08253d5473348e2f3061e0c8d84c62de537a5821 (patch)
tree06981374f0c397b45e31b74c97ed337853fe59d2 /crates/hir_def/src/nameres/path_resolution.rs
parent98a88ebb9ec46ed69dc7a3dbdc53a62ab9c1d14a (diff)
Traverse parent DefMap for `super` paths
Diffstat (limited to 'crates/hir_def/src/nameres/path_resolution.rs')
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs37
1 files changed, 28 insertions, 9 deletions
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 8ce127dde..419e465ed 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -10,8 +10,6 @@
10//! 10//!
11//! `ReachedFixedPoint` signals about this. 11//! `ReachedFixedPoint` signals about this.
12 12
13use std::iter::successors;
14
15use base_db::Edition; 13use base_db::Edition;
16use hir_expand::name; 14use hir_expand::name;
17use hir_expand::name::Name; 15use hir_expand::name::Name;
@@ -193,14 +191,35 @@ impl DefMap {
193 self.resolve_name_in_module(db, original_module, &segment, prefer_module) 191 self.resolve_name_in_module(db, original_module, &segment, prefer_module)
194 } 192 }
195 PathKind::Super(lvl) => { 193 PathKind::Super(lvl) => {
196 let m = successors(Some(original_module), |m| self.modules[*m].parent) 194 let mut module = original_module;
197 .nth(lvl as usize); 195 for i in 0..lvl {
198 if let Some(local_id) = m { 196 match self.modules[module].parent {
199 PerNs::types(self.module_id(local_id).into(), Visibility::Public) 197 Some(it) => module = it,
200 } else { 198 None => match &self.block {
201 log::debug!("super path in root module"); 199 Some(block) => {
202 return ResolvePathResult::empty(ReachedFixedPoint::Yes); 200 // Look up remaining path in parent `DefMap`
201 let new_path = ModPath {
202 kind: PathKind::Super(lvl - i),
203 segments: path.segments.clone(),
204 };
205 log::debug!("`super` path: {} -> {} in parent map", path, new_path);
206 return block.parent.resolve_path_fp_with_macro(
207 db,
208 mode,
209 block.parent_module,
210 &new_path,
211 shadow,
212 );
213 }
214 None => {
215 log::debug!("super path in root module");
216 return ResolvePathResult::empty(ReachedFixedPoint::Yes);
217 }
218 },
219 }
203 } 220 }
221
222 PerNs::types(self.module_id(module).into(), Visibility::Public)
204 } 223 }
205 PathKind::Abs => { 224 PathKind::Abs => {
206 // 2018-style absolute path -- only extern prelude 225 // 2018-style absolute path -- only extern prelude