Skip to content

Commit

Permalink
Auto merge of #18337 - dqkqd:issue-18287, r=Veykril
Browse files Browse the repository at this point in the history
fix: private items are shown in completions for modules in fn body

Close: #18287
  • Loading branch information
bors committed Oct 21, 2024
2 parents 941c443 + 8b4a94f commit a41e315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/tools/rust-analyzer/crates/hir-def/src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ impl Visibility {
let def_map_block = def_map.block_id();
loop {
match (to_module.block, def_map_block) {
// to_module is not a block, so there is no parent def map to use
// `to_module` is not a block, so there is no parent def map to use.
(None, _) => (),
// `to_module` is at `def_map`'s block, no need to move further.
(Some(a), Some(b)) if a == b => {
cov_mark::hit!(is_visible_from_same_block_def_map);
if let Some(parent) = def_map.parent() {
to_module = parent;
}
}
_ => {
if let Some(parent) = to_module.def_map(db).parent() {
Expand Down
18 changes: 18 additions & 0 deletions src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,3 +923,21 @@ fn foo() {
"#]],
);
}

#[test]
fn private_item_in_module_in_function_body() {
check_empty(
r#"
fn main() {
mod foo {
struct Private;
pub struct Public;
}
foo::$0
}
"#,
expect![[r#"
st Public Public
"#]],
);
}

0 comments on commit a41e315

Please sign in to comment.