@@ -774,31 +774,36 @@ fn clean_ty_generics<'tcx>(
774774 let mut where_predicates =
775775 where_predicates. into_iter ( ) . flat_map ( |p| clean_predicate ( * p, cx) ) . collect :: < Vec < _ > > ( ) ;
776776
777- // Type parameters have a Sized bound by default unless removed with
778- // ?Sized. Scan through the predicates and mark any type parameter with
779- // a Sized bound, removing the bounds as we find them.
777+ // In the surface language, all type parameters except `Self` have an
778+ // implicit `Sized` bound unless removed with `?Sized`.
779+ // However, in the list of where-predicates below, `Sized` appears like a
780+ // normal bound: It's either present (the type is sized) or
781+ // absent (the type is unsized) but never *maybe* (i.e. `?Sized`).
780782 //
781- // Note that associated types also have a sized bound by default, but we
783+ // This is unsuitable for rendering.
784+ // Thus, as a first step remove all `Sized` bounds that should be implicit.
785+ //
786+ // Note that associated types also have an implicit `Sized` bound but we
782787 // don't actually know the set of associated types right here so that's
783- // handled in cleaning associated types
788+ // handled when cleaning associated types.
784789 let mut sized_params = FxHashSet :: default ( ) ;
785- where_predicates. retain ( |pred| match * pred {
786- WherePredicate :: BoundPredicate { ty : Generic ( ref g) , ref bounds, .. } => {
787- if bounds. iter ( ) . any ( |b| b. is_sized_bound ( cx) ) {
788- sized_params. insert ( * g) ;
789- false
790- } else {
791- true
792- }
790+ where_predicates. retain ( |pred| {
791+ if let WherePredicate :: BoundPredicate { ty : Generic ( g) , bounds, .. } = pred
792+ && * g != kw:: SelfUpper
793+ && bounds. iter ( ) . any ( |b| b. is_sized_bound ( cx) )
794+ {
795+ sized_params. insert ( * g) ;
796+ false
797+ } else {
798+ true
793799 }
794- _ => true ,
795800 } ) ;
796801
797- // Run through the type parameters again and insert a ?Sized
798- // unbound for any we didn't find to be Sized.
802+ // As a final step, go through the type parameters again and insert a
803+ // `?Sized` bound for each one we didn't find to be ` Sized` .
799804 for tp in & stripped_params {
800- if matches ! ( tp . kind , types:: GenericParamDefKind :: Type { .. } )
801- && !sized_params. contains ( & tp. name )
805+ if let types:: GenericParamDefKind :: Type { .. } = tp . kind
806+ && !sized_params. contains ( & tp. name )
802807 {
803808 where_predicates. push ( WherePredicate :: BoundPredicate {
804809 ty : Type :: Generic ( tp. name ) ,
0 commit comments