aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/find_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/find_path.rs')
-rw-r--r--crates/hir_def/src/find_path.rs27
1 files changed, 8 insertions, 19 deletions
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index c01b6daf2..94a1d567d 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -53,12 +53,8 @@ fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option<
53 Some(ModPath::from_segments(PathKind::Super(0), Vec::new())) 53 Some(ModPath::from_segments(PathKind::Super(0), Vec::new()))
54 } else if let Some(parent_id) = def_map[from.local_id].parent { 54 } else if let Some(parent_id) = def_map[from.local_id].parent {
55 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly) 55 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
56 if item 56 let parent_id = def_map.module_id(parent_id);
57 == ItemInNs::Types(ModuleDefId::ModuleId(ModuleId { 57 if item == ItemInNs::Types(ModuleDefId::ModuleId(parent_id)) {
58 krate: from.krate,
59 local_id: parent_id,
60 }))
61 {
62 Some(ModPath::from_segments(PathKind::Super(1), Vec::new())) 58 Some(ModPath::from_segments(PathKind::Super(1), Vec::new()))
63 } else { 59 } else {
64 None 60 None
@@ -120,12 +116,8 @@ fn find_path_inner(
120 } 116 }
121 117
122 // - if the item is the crate root, return `crate` 118 // - if the item is the crate root, return `crate`
123 if item 119 let root = def_map.module_id(def_map.root());
124 == ItemInNs::Types(ModuleDefId::ModuleId(ModuleId { 120 if item == ItemInNs::Types(ModuleDefId::ModuleId(root)) {
125 krate: from.krate,
126 local_id: def_map.root(),
127 }))
128 {
129 return Some(ModPath::from_segments(PathKind::Crate, Vec::new())); 121 return Some(ModPath::from_segments(PathKind::Crate, Vec::new()));
130 } 122 }
131 123
@@ -175,7 +167,7 @@ fn find_path_inner(
175 167
176 // - otherwise, look for modules containing (reexporting) it and import it from one of those 168 // - otherwise, look for modules containing (reexporting) it and import it from one of those
177 169
178 let crate_root = ModuleId { local_id: def_map.root(), krate: from.krate }; 170 let crate_root = def_map.module_id(def_map.root());
179 let crate_attrs = db.attrs(crate_root.into()); 171 let crate_attrs = db.attrs(crate_root.into());
180 let prefer_no_std = crate_attrs.by_key("no_std").exists(); 172 let prefer_no_std = crate_attrs.by_key("no_std").exists();
181 let mut best_path = None; 173 let mut best_path = None;
@@ -288,14 +280,11 @@ fn find_local_import_locations(
288 // Compute the initial worklist. We start with all direct child modules of `from` as well as all 280 // Compute the initial worklist. We start with all direct child modules of `from` as well as all
289 // of its (recursive) parent modules. 281 // of its (recursive) parent modules.
290 let data = &def_map[from.local_id]; 282 let data = &def_map[from.local_id];
291 let mut worklist = data 283 let mut worklist =
292 .children 284 data.children.values().map(|child| def_map.module_id(*child)).collect::<Vec<_>>();
293 .values()
294 .map(|child| ModuleId { krate: from.krate, local_id: *child })
295 .collect::<Vec<_>>();
296 let mut parent = data.parent; 285 let mut parent = data.parent;
297 while let Some(p) = parent { 286 while let Some(p) = parent {
298 worklist.push(ModuleId { krate: from.krate, local_id: p }); 287 worklist.push(def_map.module_id(p));
299 parent = def_map[p].parent; 288 parent = def_map[p].parent;
300 } 289 }
301 290