Skip to content

Commit a41e315

Browse files
committed
Auto merge of rust-lang#18337 - dqkqd:issue-18287, r=Veykril
fix: private items are shown in completions for modules in fn body Close: rust-lang#18287
2 parents 941c443 + 8b4a94f commit a41e315

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/tools/rust-analyzer/crates/hir-def/src/visibility.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,11 @@ impl Visibility {
139139
let def_map_block = def_map.block_id();
140140
loop {
141141
match (to_module.block, def_map_block) {
142-
// to_module is not a block, so there is no parent def map to use
142+
// `to_module` is not a block, so there is no parent def map to use.
143143
(None, _) => (),
144+
// `to_module` is at `def_map`'s block, no need to move further.
144145
(Some(a), Some(b)) if a == b => {
145146
cov_mark::hit!(is_visible_from_same_block_def_map);
146-
if let Some(parent) = def_map.parent() {
147-
to_module = parent;
148-
}
149147
}
150148
_ => {
151149
if let Some(parent) = to_module.def_map(db).parent() {

src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,21 @@ fn foo() {
923923
"#]],
924924
);
925925
}
926+
927+
#[test]
928+
fn private_item_in_module_in_function_body() {
929+
check_empty(
930+
r#"
931+
fn main() {
932+
mod foo {
933+
struct Private;
934+
pub struct Public;
935+
}
936+
foo::$0
937+
}
938+
"#,
939+
expect![[r#"
940+
st Public Public
941+
"#]],
942+
);
943+
}

0 commit comments

Comments
 (0)