Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/find_path.rs')
-rw-r--r--crates/hir-def/src/find_path.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs
index 4737b48703..e8086be86f 100644
--- a/crates/hir-def/src/find_path.rs
+++ b/crates/hir-def/src/find_path.rs
@@ -551,7 +551,18 @@ fn find_local_import_locations(
if let Some((name, vis)) = data.scope.name_of(item) {
if vis.is_visible_from(db, from) {
let is_private = match vis {
- Visibility::Module(private_to) => private_to.local_id == module.local_id,
+ Visibility::Module(private_mod, private_vis) => {
+ if private_mod == def_map.module_id(DefMap::ROOT)
+ && private_vis.is_explicit()
+ {
+ // Treat `pub(crate)` imports as non-private, so
+ // that we suggest adding `use crate::Foo;` instead
+ // of `use crate::foo::Foo;` etc.
+ false
+ } else {
+ private_mod.local_id == module.local_id
+ }
+ }
Visibility::Public => false,
};
let is_original_def = match item.as_module_def_id() {
@@ -1022,6 +1033,24 @@ $0
}
#[test]
+ fn promote_pub_crate_imports() {
+ check_found_path(
+ r#"
+//- /main.rs
+mod foo;
+pub mod bar { pub struct S; }
+pub(crate) use bar::S;
+//- /foo.rs
+$0
+ "#,
+ "crate::S",
+ "crate::S",
+ "crate::S",
+ "crate::S",
+ );
+ }
+
+ #[test]
fn import_cycle() {
check_found_path(
r#"