Skip to content

fix: do not resolve prelude within block modules #17352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/hir-def/src/nameres/path_resolution.rs
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 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;
}
}
"#,
);
}
}