Fix primitive shadowing with inner items
This commit is contained in:
parent
e53919a425
commit
543d4ef7c5
2 changed files with 25 additions and 1 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue