Skip to content

Commit 4f3d862

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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
2 parents 5ae7815 + d54745a commit 4f3d862

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

crates/hir-def/src/item_tree/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,15 @@ struct S<#[cfg(never)] T>;
370370
"#]],
371371
)
372372
}
373+
374+
#[test]
375+
fn pub_self() {
376+
check(
377+
r#"
378+
pub(self) struct S;
379+
"#,
380+
expect![[r#"
381+
pub(self) struct S;
382+
"#]],
383+
)
384+
}

crates/hir-def/src/nameres/path_resolution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl DefMap {
9696
let types = result.take_types()?;
9797
match types {
9898
ModuleDefId::ModuleId(m) => Visibility::Module(m),
99+
// error: visibility needs to refer to module
99100
_ => {
100-
// error: visibility needs to refer to module
101101
return None;
102102
}
103103
}

crates/hir-def/src/visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl RawVisibility {
7373
RawVisibility::Module(path)
7474
}
7575
ast::VisibilityKind::PubSelf => {
76-
let path = ModPath::from_kind(PathKind::Plain);
76+
let path = ModPath::from_kind(PathKind::Super(0));
7777
RawVisibility::Module(path)
7878
}
7979
ast::VisibilityKind::Pub => RawVisibility::Public,

crates/ide-completion/src/tests/special.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,30 @@ fn here_we_go() {
12861286
);
12871287
}
12881288

1289+
#[test]
1290+
fn completes_only_public() {
1291+
check(
1292+
r#"
1293+
//- /e.rs
1294+
pub(self) fn i_should_be_hidden() {}
1295+
pub(in crate::e) fn i_should_also_be_hidden() {}
1296+
pub fn i_am_public () {}
1297+
1298+
//- /lib.rs crate:krate
1299+
pub mod e;
1300+
1301+
//- /main.rs deps:krate crate:main
1302+
use krate::e;
1303+
fn main() {
1304+
e::$0
1305+
}"#,
1306+
expect![
1307+
"fn i_am_public() fn()
1308+
"
1309+
],
1310+
)
1311+
}
1312+
12891313
#[test]
12901314
fn completion_filtering_excludes_non_identifier_doc_aliases() {
12911315
check_edit(

0 commit comments

Comments
 (0)