about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-08 11:02:08 +0000
committerbors <bors@rust-lang.org>2023-12-08 11:02:08 +0000
commit4f3d862fcfa853f49467f0f81eab2686e65c86ee (patch)
tree586fb7cbc5fb2e9602098a33e4d31b1e6fab2be6
parent5ae781562e412114fb72b5be7d26af5bb86c29d5 (diff)
parentd54745aed3a747a907e2fea3528f98c4d4701345 (diff)
downloadrust-4f3d862fcfa853f49467f0f81eab2686e65c86ee.tar.gz
rust-4f3d862fcfa853f49467f0f81eab2686e65c86ee.zip
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
-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 4180f817209..96c65b941c1 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 4c1b8f306c5..be3438e427d 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 ab9266aa60f..f5803653c73 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 d3dbd7cc227..28c9bffc5ec 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",