From 543d4ef7c536648704848f6df11c4a1ef31e11bc Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 16 Apr 2021 19:28:22 +0200 Subject: Fix primitive shadowing with inner items --- crates/hir_def/src/nameres/path_resolution.rs | 8 +++++++- crates/hir_ty/src/tests/simple.rs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index ccc9f22eb..c984148c3 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -387,7 +387,13 @@ impl DefMap { .get_legacy_macro(name) .map_or_else(PerNs::none, |m| PerNs::macros(m, Visibility::Public)); let from_scope = self[module].scope.get(name); - let from_builtin = BUILTIN_SCOPE.get(name).copied().unwrap_or_else(PerNs::none); + let from_builtin = match self.block { + Some(_) => { + // Only resolve to builtins in the root `DefMap`. + PerNs::none() + } + None => BUILTIN_SCOPE.get(name).copied().unwrap_or_else(PerNs::none), + }; let from_scope_or_builtin = match shadow { BuiltinShadowMode::Module => from_scope.or(from_builtin), BuiltinShadowMode::Other => { diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 84c5c05fd..5948d0bc2 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs @@ -1764,6 +1764,24 @@ fn main() { ); } +#[test] +fn shadowing_primitive_with_inner_items() { + check_types( + r#" +struct i32; +struct Foo; + +impl i32 { fn foo(&self) -> Foo { Foo } } + +fn main() { + fn inner() {} + let x: i32 = i32; + x.foo(); + //^ Foo +}"#, + ); +} + #[test] fn not_shadowing_primitive_by_module() { check_types( -- cgit v1.2.3