Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
The crux of the bug fix.
Update: review feedback
Update: placate tidy
  • Loading branch information
pnkfelix committed Oct 3, 2019
commit 3a4921cde162af1ffbb2fbff4b395408eab1deab
13 changes: 13 additions & 0 deletions src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with the phrasing (although the conclusion is similar) - see #61631 (comment)

In short, Self expands to/aliases Adt<A, B, C, ...>, referring to all the ADTs' parameters, and we shouldn't allow writing Self where we wouldn't allow Adt<A, B, C, ...>.

// 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()
Expand Down