Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #17352 - roife:fix-issue-17338, r=Veykril
fix: do not resolve prelude within block modules
fix #17338 (continuing from #17251).
In #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)
| -rw-r--r-- | crates/hir-def/src/nameres/path_resolution.rs | 7 | ||||
| -rw-r--r-- | crates/ide/src/goto_definition.rs | 24 |
2 files changed, 30 insertions, 1 deletions
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs index 863ccec885..e797d19223 100644 --- a/crates/hir-def/src/nameres/path_resolution.rs +++ b/crates/hir-def/src/nameres/path_resolution.rs @@ -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) diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 76b80fcefa..f57cb1cb73 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -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; + } +} + "#, + ); + } } |