diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-20 22:21:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-20 22:21:57 +0200 |
| commit | d502b1c8e411e7de77d7146a2d7ba61b572a7309 (patch) | |
| tree | f342ff323458fbb42c360fc2719b54084893489d | |
| parent | 2e58d62fec255997c89b53601fd4a4500e9aecb6 (diff) | |
| parent | 78d0e08504a30e5ff8b8e0ba88126af95a16a398 (diff) | |
| download | rust-d502b1c8e411e7de77d7146a2d7ba61b572a7309.tar.gz rust-d502b1c8e411e7de77d7146a2d7ba61b572a7309.zip | |
Rollup merge of #129270 - compiler-errors:inner-generics-shadowing, r=petrochenkov
Don't consider locals to shadow inner items' generics We don't want to consider the bindings from a `RibKind::Module` itself, because for an inner item that module will contain the local bindings from the function body or wherever else the inner item is being defined. Fixes #129265 r? petrochenkov
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 6 | ||||
| -rw-r--r-- | tests/ui/resolve/local-shadows-inner-generic.rs | 8 |
2 files changed, 11 insertions, 3 deletions
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 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { // 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<a> { field: a, }; +} |
