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
This commit is contained in:
commit
d502b1c8e4
2 changed files with 11 additions and 3 deletions
|
@ -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.
|
// We also can't shadow bindings from associated parent items.
|
||||||
for ns in [ValueNS, TypeNS] {
|
for ns in [ValueNS, TypeNS] {
|
||||||
for parent_rib in self.ribs[ns].iter().rev() {
|
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
|
// Break at mod level, to account for nested items which are
|
||||||
// allowed to shadow generic param names.
|
// allowed to shadow generic param names.
|
||||||
if matches!(parent_rib.kind, RibKind::Module(..)) {
|
if matches!(parent_rib.kind, RibKind::Module(..)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seen_bindings
|
||||||
|
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
tests/ui/resolve/local-shadows-inner-generic.rs
Normal file
8
tests/ui/resolve/local-shadows-inner-generic.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let a = 1;
|
||||||
|
struct Foo<a> { field: a, };
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue