Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #15486 - petr-tik:n15134_hide_private_from_autocomplete_2, r=Veykril
fix: Fix item tree lowering pub(self) to pub() Prior to this, the item tree lowered `pub(self)` visibility to `pub()` Fix #15134 - tested with a unit test and a manual end-to-end test of building rust-analyzer from my branch and opening the reproduction repository
bors 2023-12-08
parent 5ae7815 · parent d54745a · commit 4f3d862
-rw-r--r--crates/hir-def/src/item_tree/tests.rs12
-rw-r--r--crates/hir-def/src/nameres/path_resolution.rs2
-rw-r--r--crates/hir-def/src/visibility.rs2
-rw-r--r--crates/ide-completion/src/tests/special.rs24
4 files changed, 38 insertions, 2 deletions
diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs
index 4180f81720..96c65b941c 100644
--- a/crates/hir-def/src/item_tree/tests.rs
+++ b/crates/hir-def/src/item_tree/tests.rs
@@ -370,3 +370,15 @@ struct S<#[cfg(never)] T>;
"#]],
)
}
+
+#[test]
+fn pub_self() {
+ check(
+ r#"
+pub(self) struct S;
+ "#,
+ expect![[r#"
+ pub(self) struct S;
+ "#]],
+ )
+}
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs
index 4c1b8f306c..be3438e427 100644
--- a/crates/hir-def/src/nameres/path_resolution.rs
+++ b/crates/hir-def/src/nameres/path_resolution.rs
@@ -96,8 +96,8 @@ impl DefMap {
let types = result.take_types()?;
match types {
ModuleDefId::ModuleId(m) => Visibility::Module(m),
+ // error: visibility needs to refer to module
_ => {
- // error: visibility needs to refer to module
return None;
}
}
diff --git a/crates/hir-def/src/visibility.rs b/crates/hir-def/src/visibility.rs
index ab9266aa60..f5803653c7 100644
--- a/crates/hir-def/src/visibility.rs
+++ b/crates/hir-def/src/visibility.rs
@@ -73,7 +73,7 @@ impl RawVisibility {
RawVisibility::Module(path)
}
ast::VisibilityKind::PubSelf => {
- let path = ModPath::from_kind(PathKind::Plain);
+ let path = ModPath::from_kind(PathKind::Super(0));
RawVisibility::Module(path)
}
ast::VisibilityKind::Pub => RawVisibility::Public,
diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs
index d3dbd7cc22..28c9bffc5e 100644
--- a/crates/ide-completion/src/tests/special.rs
+++ b/crates/ide-completion/src/tests/special.rs
@@ -1287,6 +1287,30 @@ fn here_we_go() {
}
#[test]
+fn completes_only_public() {
+ check(
+ r#"
+//- /e.rs
+pub(self) fn i_should_be_hidden() {}
+pub(in crate::e) fn i_should_also_be_hidden() {}
+pub fn i_am_public () {}
+
+//- /lib.rs crate:krate
+pub mod e;
+
+//- /main.rs deps:krate crate:main
+use krate::e;
+fn main() {
+ e::$0
+}"#,
+ expect![
+ "fn i_am_public() fn()
+"
+ ],
+ )
+}
+
+#[test]
fn completion_filtering_excludes_non_identifier_doc_aliases() {
check_edit(
"PartialOrdcmporder",