Skip to content

Commit

Permalink
fix: private items are shown in completions for modules in fn body
Browse files Browse the repository at this point in the history
  • Loading branch information
dqkqd committed Oct 21, 2024
1 parent 0c37404 commit 8b4a94f
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 8b4a94f

Please sign in to comment.