From 78d0e08504a30e5ff8b8e0ba88126af95a16a398 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 19 Aug 2024 10:57:03 -0400 Subject: [PATCH] Don't consider RibKind::Module's bindings when checking generics shadowing --- compiler/rustc_resolve/src/late.rs | 6 +++--- tests/ui/resolve/local-shadows-inner-generic.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/ui/resolve/local-shadows-inner-generic.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 4a70fc0f308..40fdb01a72c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2677,14 +2677,14 @@ fn with_generic_param_rib<'c, F>( // We also can't shadow bindings from associated parent items. for ns in [ValueNS, TypeNS] { for parent_rib in self.ribs[ns].iter().rev() { - seen_bindings - .extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span))); - // Break at mod level, to account for nested items which are // allowed to shadow generic param names. if matches!(parent_rib.kind, RibKind::Module(..)) { break; } + + seen_bindings + .extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span))); } } diff --git a/tests/ui/resolve/local-shadows-inner-generic.rs b/tests/ui/resolve/local-shadows-inner-generic.rs new file mode 100644 index 00000000000..d9145b9fe2c --- /dev/null +++ b/tests/ui/resolve/local-shadows-inner-generic.rs @@ -0,0 +1,8 @@ +//@ check-pass + +#![allow(non_camel_case_types)] + +pub fn main() { + let a = 1; + struct Foo { field: a, }; +}