aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-30 17:42:24 +0100
committerGitHub <[email protected]>2021-04-30 17:42:24 +0100
commit6b2b6c1b57d3f0432424de6b828a3ef9150ad825 (patch)
tree02f41c4fdb0615f27370e9ea4c6837d3cb66421c /crates/hir_def
parentb5b4a1f23dd4d544eec0699bda9df39235617711 (diff)
parent6873920c4f371db13e221d7ba9a599ed7efb95dd (diff)
Merge #8698
8698: fix: search only crate-level prelude when looking for an item r=jonas-schievink a=jonas-schievink Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8688 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def')
-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}