Skip to content

Commit 3a4921c

Browse files
committed
The crux of the bug fix.
Update: review feedback Update: placate tidy
1 parent 0221e26 commit 3a4921c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc_resolve/late.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,19 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
468468
}
469469
}));
470470

471+
// rust-lang/rust#61631: The type `Self` is essentially
472+
// another type parameter. For ADTs, we consider it
473+
// well-defined only after all of the ADT type parameters have
474+
// been provided. Therefore, we do not allow use of `Self`
475+
// anywhere in ADT type parameter defaults.
476+
//
477+
// (We however cannot ban `Self` for defaults on *all* generic
478+
// lists; e.g. trait generics can usefully refer to `Self`,
479+
// such as in the case of `trait Add<Rhs = Self>`.)
480+
if self.current_self_item.is_some() { // (`Some` if + only if we are in ADT's generics.)
481+
default_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
482+
}
483+
471484
// We also ban access to type parameters for use as the types of const parameters.
472485
let mut const_ty_param_ban_rib = Rib::new(TyParamAsConstParamTy);
473486
const_ty_param_ban_rib.bindings.extend(generics.params.iter()

0 commit comments

Comments
 (0)