aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/find_path.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index dc3f2908f..c06a37294 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -130,7 +130,8 @@ fn find_path_inner(
130 } 130 }
131 131
132 // - if the item is the crate root of a dependency crate, return the name from the extern prelude 132 // - if the item is the crate root of a dependency crate, return the name from the extern prelude
133 for (name, def_id) in root.def_map(db).extern_prelude() { 133 let root_def_map = root.def_map(db);
134 for (name, def_id) in root_def_map.extern_prelude() {
134 if item == ItemInNs::Types(*def_id) { 135 if item == ItemInNs::Types(*def_id) {
135 let name = scope_name.unwrap_or_else(|| name.clone()); 136 let name = scope_name.unwrap_or_else(|| name.clone());
136 return Some(ModPath::from_segments(PathKind::Plain, vec![name])); 137 return Some(ModPath::from_segments(PathKind::Plain, vec![name]));
@@ -138,7 +139,8 @@ fn find_path_inner(
138 } 139 }
139 140
140 // - if the item is in the prelude, return the name from there 141 // - if the item is in the prelude, return the name from there
141 if let Some(prelude_module) = def_map.prelude() { 142 if let Some(prelude_module) = root_def_map.prelude() {
143 // Preludes in block DefMaps are ignored, only the crate DefMap is searched
142 let prelude_def_map = prelude_module.def_map(db); 144 let prelude_def_map = prelude_module.def_map(db);
143 let prelude_scope: &crate::item_scope::ItemScope = 145 let prelude_scope: &crate::item_scope::ItemScope =
144 &prelude_def_map[prelude_module.local_id].scope; 146 &prelude_def_map[prelude_module.local_id].scope;
@@ -1057,4 +1059,28 @@ fn f() {
1057 "dep", 1059 "dep",
1058 ); 1060 );
1059 } 1061 }
1062
1063 #[test]
1064 fn prelude_with_inner_items() {
1065 check_found_path(
1066 r#"
1067//- /main.rs crate:main deps:std
1068fn f() {
1069 fn inner() {}
1070 $0
1071}
1072//- /std.rs crate:std
1073pub mod prelude {
1074 pub enum Option { None }
1075 pub use Option::*;
1076}
1077#[prelude_import]
1078pub use prelude::*;
1079 "#,
1080 "None",
1081 "None",
1082 "None",
1083 "None",
1084 );
1085 }
1060} 1086}