Skip to content

Commit

Permalink
Auto merge of #15486 - petr-tik:n15134_hide_private_from_autocomplete…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
bors committed Dec 8, 2023
2 parents 5ae7815 + d54745a commit 4f3d862
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions crates/hir-def/src/item_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"#]],
)
}
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions crates/ide-completion/src/tests/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,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(
Expand Down

0 comments on commit 4f3d862

Please sign in to comment.