From 3a4921cde162af1ffbb2fbff4b395408eab1deab Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 27 Sep 2019 14:45:19 +0200 Subject: [PATCH] The crux of the bug fix. Update: review feedback Update: placate tidy --- src/librustc_resolve/late.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 33a85c6c7702..93c96b9f75ba 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -468,6 +468,19 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { } })); + // rust-lang/rust#61631: The type `Self` is essentially + // another type parameter. For ADTs, we consider it + // well-defined only after all of the ADT type parameters have + // been provided. Therefore, we do not allow use of `Self` + // anywhere in ADT type parameter defaults. + // + // (We however cannot ban `Self` for defaults on *all* generic + // lists; e.g. trait generics can usefully refer to `Self`, + // such as in the case of `trait Add`.) + if self.current_self_item.is_some() { // (`Some` if + only if we are in ADT's generics.) + default_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err); + } + // We also ban access to type parameters for use as the types of const parameters. let mut const_ty_param_ban_rib = Rib::new(TyParamAsConstParamTy); const_ty_param_ban_rib.bindings.extend(generics.params.iter()