Detect non-lifetime binder params shadowing item params
This commit is contained in:
parent
4db3d12e6f
commit
454c600004
6 changed files with 89 additions and 17 deletions
|
@ -2671,17 +2671,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
// Store all seen lifetimes names from outer scopes.
|
||||
let mut seen_lifetimes = FxHashSet::default();
|
||||
|
||||
// We also can't shadow bindings from the parent item
|
||||
if let RibKind::AssocItem = kind {
|
||||
let mut add_bindings_for_ns = |ns| {
|
||||
let parent_rib = self.ribs[ns]
|
||||
.iter()
|
||||
.rfind(|r| matches!(r.kind, RibKind::Item(..)))
|
||||
.expect("associated item outside of an item");
|
||||
// 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)));
|
||||
};
|
||||
add_bindings_for_ns(ValueNS);
|
||||
add_bindings_for_ns(TypeNS);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Forbid shadowing lifetime bindings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue