about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2019-09-27 14:45:19 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2019-10-03 13:54:07 +0200
commit3a4921cde162af1ffbb2fbff4b395408eab1deab (patch)
tree98440a893c8ab59f7931fcfefd5d57746c2f8cc0
parent0221e265621a5fcc68ca62bdcdeabad1882a0e9a (diff)
downloadrust-3a4921cde162af1ffbb2fbff4b395408eab1deab.tar.gz
rust-3a4921cde162af1ffbb2fbff4b395408eab1deab.zip
The crux of the bug fix.
Update: review feedback
Update: placate tidy
-rw-r--r--src/librustc_resolve/late.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs
index 33a85c6c770..93c96b9f75b 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<Rhs = Self>`.)
+        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()