mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Merge #8820
8820: fix: Return absolute paths in find_path if crate start is ambiguous r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
908cd23f81
@ -5,10 +5,10 @@ use std::iter;
|
|||||||
use hir_expand::name::{known, AsName, Name};
|
use hir_expand::name::{known, AsName, Name};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::nameres::DefMap;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::ItemInNs,
|
item_scope::ItemInNs,
|
||||||
|
nameres::DefMap,
|
||||||
path::{ModPath, PathKind},
|
path::{ModPath, PathKind},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
ModuleDefId, ModuleId,
|
ModuleDefId, ModuleId,
|
||||||
@ -134,7 +134,16 @@ fn find_path_inner(
|
|||||||
for (name, def_id) in root_def_map.extern_prelude() {
|
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]));
|
|
||||||
|
let name_already_occupied_in_type_ns = def_map
|
||||||
|
.with_ancestor_maps(db, from.local_id, &mut |def_map, local_id| {
|
||||||
|
def_map[local_id].scope.get(&name).take_types().filter(|&id| id != *def_id)
|
||||||
|
})
|
||||||
|
.is_some();
|
||||||
|
return Some(ModPath::from_segments(
|
||||||
|
if name_already_occupied_in_type_ns { PathKind::Abs } else { PathKind::Plain },
|
||||||
|
vec![name],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,6 +966,32 @@ mod bar {
|
|||||||
println!("Hallo");
|
println!("Hallo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn uses_abs_path_with_extern_crate_clash() {
|
||||||
|
check_assist(
|
||||||
|
auto_import,
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:foo
|
||||||
|
mod foo {}
|
||||||
|
|
||||||
|
const _: () = {
|
||||||
|
Foo$0
|
||||||
|
};
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub struct Foo
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
use ::foo::Foo;
|
||||||
|
|
||||||
|
mod foo {}
|
||||||
|
|
||||||
|
const _: () = {
|
||||||
|
Foo
|
||||||
|
};
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user