Skip to content

Commit 49dd2d3

Browse files
committed
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)
2 parents 56a298b + 07fde07 commit 49dd2d3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/tools/rust-analyzer/crates/hir-def/src/nameres/path_resolution.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@ impl DefMap {
493493
)
494494
})
495495
};
496-
let prelude = || self.resolve_in_prelude(db, name);
496+
let prelude = || {
497+
if self.block.is_some() && module == DefMap::ROOT {
498+
return PerNs::none();
499+
}
500+
self.resolve_in_prelude(db, name)
501+
};
497502

498503
from_legacy_macro
499504
.or(from_scope_or_builtin)

src/tools/rust-analyzer/crates/ide/src/goto_definition.rs

+24
Original file line numberDiff line numberDiff line change
@@ -2289,4 +2289,28 @@ macro_rules! baz {
22892289
"#,
22902290
);
22912291
}
2292+
2293+
#[test]
2294+
fn goto_shadowed_preludes_in_block_module() {
2295+
check(
2296+
r#"
2297+
//- /main.rs crate:main edition:2021 deps:core
2298+
pub struct S;
2299+
//^
2300+
2301+
fn main() {
2302+
fn f() -> S$0 {
2303+
fn inner() {} // forces a block def map
2304+
return S;
2305+
}
2306+
}
2307+
//- /core.rs crate:core
2308+
pub mod prelude {
2309+
pub mod rust_2021 {
2310+
pub enum S;
2311+
}
2312+
}
2313+
"#,
2314+
);
2315+
}
22922316
}

0 commit comments

Comments
 (0)