Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't consider locals to shadow inner items' generics #129270

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/ui/resolve/local-shadows-inner-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass

#![allow(non_camel_case_types)]

pub fn main() {
let a = 1;
struct Foo<a> { field: a, };
}
Loading