Skip to content

Commit 47b40b6

Browse files
Merge #8545
8545: Fix primitive shadowing with inner items r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents e53919a + 543d4ef commit 47b40b6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

crates/hir_def/src/nameres/path_resolution.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,13 @@ impl DefMap {
387387
.get_legacy_macro(name)
388388
.map_or_else(PerNs::none, |m| PerNs::macros(m, Visibility::Public));
389389
let from_scope = self[module].scope.get(name);
390-
let from_builtin = BUILTIN_SCOPE.get(name).copied().unwrap_or_else(PerNs::none);
390+
let from_builtin = match self.block {
391+
Some(_) => {
392+
// Only resolve to builtins in the root `DefMap`.
393+
PerNs::none()
394+
}
395+
None => BUILTIN_SCOPE.get(name).copied().unwrap_or_else(PerNs::none),
396+
};
391397
let from_scope_or_builtin = match shadow {
392398
BuiltinShadowMode::Module => from_scope.or(from_builtin),
393399
BuiltinShadowMode::Other => {

crates/hir_ty/src/tests/simple.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,24 @@ fn main() {
17641764
);
17651765
}
17661766

1767+
#[test]
1768+
fn shadowing_primitive_with_inner_items() {
1769+
check_types(
1770+
r#"
1771+
struct i32;
1772+
struct Foo;
1773+
1774+
impl i32 { fn foo(&self) -> Foo { Foo } }
1775+
1776+
fn main() {
1777+
fn inner() {}
1778+
let x: i32 = i32;
1779+
x.foo();
1780+
//^ Foo
1781+
}"#,
1782+
);
1783+
}
1784+
17671785
#[test]
17681786
fn not_shadowing_primitive_by_module() {
17691787
check_types(

0 commit comments

Comments
 (0)