mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
find_path: check only crate-level prelude
This commit is contained in:
parent
b5b4a1f23d
commit
6873920c4f
1 changed files with 28 additions and 2 deletions
|
@ -130,7 +130,8 @@ fn find_path_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
|
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
|
||||||
for (name, def_id) in root.def_map(db).extern_prelude() {
|
let root_def_map = root.def_map(db);
|
||||||
|
for (name, def_id) in root_def_map.extern_prelude() {
|
||||||
if item == ItemInNs::Types(*def_id) {
|
if item == ItemInNs::Types(*def_id) {
|
||||||
let name = scope_name.unwrap_or_else(|| name.clone());
|
let name = scope_name.unwrap_or_else(|| name.clone());
|
||||||
return Some(ModPath::from_segments(PathKind::Plain, vec![name]));
|
return Some(ModPath::from_segments(PathKind::Plain, vec![name]));
|
||||||
|
@ -138,7 +139,8 @@ fn find_path_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - if the item is in the prelude, return the name from there
|
// - if the item is in the prelude, return the name from there
|
||||||
if let Some(prelude_module) = def_map.prelude() {
|
if let Some(prelude_module) = root_def_map.prelude() {
|
||||||
|
// Preludes in block DefMaps are ignored, only the crate DefMap is searched
|
||||||
let prelude_def_map = prelude_module.def_map(db);
|
let prelude_def_map = prelude_module.def_map(db);
|
||||||
let prelude_scope: &crate::item_scope::ItemScope =
|
let prelude_scope: &crate::item_scope::ItemScope =
|
||||||
&prelude_def_map[prelude_module.local_id].scope;
|
&prelude_def_map[prelude_module.local_id].scope;
|
||||||
|
@ -1057,4 +1059,28 @@ fn f() {
|
||||||
"dep",
|
"dep",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn prelude_with_inner_items() {
|
||||||
|
check_found_path(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
fn f() {
|
||||||
|
fn inner() {}
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
pub mod prelude {
|
||||||
|
pub enum Option { None }
|
||||||
|
pub use Option::*;
|
||||||
|
}
|
||||||
|
#[prelude_import]
|
||||||
|
pub use prelude::*;
|
||||||
|
"#,
|
||||||
|
"None",
|
||||||
|
"None",
|
||||||
|
"None",
|
||||||
|
"None",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue