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)
This commit is contained in:
bors 2024-06-06 09:40:39 +00:00
commit af488c971f
2 changed files with 30 additions and 1 deletions

View file

@ -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)

View file

@ -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;
}
}
"#,
);
}
}