mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
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:
commit
af488c971f
2 changed files with 30 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue