Skip to content

Commit

Permalink
Auto merge of rust-lang#17352 - roife:fix-issue-17338, r=Veykril
Browse files Browse the repository at this point in the history
fix: do not resolve prelude within block modules

fix rust-lang#17338 (continuing from rust-lang#17251).

In rust-lang#17251, we injected preludes into non-top-level modules, which leading to r-a to directly resolve names in preludes in block modules. This PR fix it by checking whether the module is a pseudo-module introduced by blocks. (similar to what we do for extern preludes)
  • Loading branch information
bors committed Jun 6, 2024
2 parents 56a298b + 07fde07 commit 49dd2d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ impl DefMap {
)
})
};
let prelude = || self.resolve_in_prelude(db, name);
let prelude = || {
if self.block.is_some() && module == DefMap::ROOT {
return PerNs::none();
}
self.resolve_in_prelude(db, name)
};

from_legacy_macro
.or(from_scope_or_builtin)
Expand Down
24 changes: 24 additions & 0 deletions src/tools/rust-analyzer/crates/ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2289,4 +2289,28 @@ macro_rules! baz {
"#,
);
}

#[test]
fn goto_shadowed_preludes_in_block_module() {
check(
r#"
//- /main.rs crate:main edition:2021 deps:core
pub struct S;
//^
fn main() {
fn f() -> S$0 {
fn inner() {} // forces a block def map
return S;
}
}
//- /core.rs crate:core
pub mod prelude {
pub mod rust_2021 {
pub enum S;
}
}
"#,
);
}
}

0 comments on commit 49dd2d3

Please sign in to comment.