@@ -770,26 +770,40 @@ fn clean_ty_generics<'tcx>(
770770 // FIXME: does this handle Sized/?Sized properly?
771771 for ( index, predicates) in apits {
772772 // FIXME: fix up API of clean_pred instead
773- let mut where_predicates = modern:: clean_predicates ( cx, predicates) ;
774- let Some ( WherePredicate :: BoundPredicate { bounds, .. } ) = where_predicates. pop ( ) else {
775- unreachable ! ( )
773+ let mut where_predicates =
774+ modern:: clean_predicates ( cx, predicates, & mut modern:: Apit :: default ( ) ) ;
775+ let mut bounds = match where_predicates. pop ( ) {
776+ Some ( WherePredicate :: BoundPredicate { bounds, .. } ) => bounds,
777+ Some ( _) => unreachable ! ( ) ,
778+ None => Vec :: new ( ) ,
776779 } ;
780+
781+ // Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
782+ if bounds. iter ( ) . all ( |bound| !bound. is_trait_bound ( ) ) {
783+ bounds. insert ( 0 , GenericBound :: sized ( cx) ) ;
784+ }
777785 cx. impl_trait_bounds . insert ( index. into ( ) , bounds) ;
778786 }
779787
780- let where_predicates = modern:: clean_predicates ( cx, predicates) ;
788+ let mut cleaner = modern:: WhereClause :: default ( ) ;
789+ let mut where_predicates = modern:: clean_predicates ( cx, predicates, & mut cleaner) ;
781790
782- // FIXME: we no longer have access to `sized: UnordMap`
783- // for param in &generics.own_params {
784- // if !sized.contains(¶m.index) {
785- // // FIXME: is this correct if we have parent generics?
786- // where_predicates.push(WherePredicate::BoundPredicate {
787- // ty: Type::Generic(param.name),
788- // bounds: vec![GenericBound::maybe_sized(cx)],
789- // bound_params: Vec::new(),
790- // })
791- // }
792- // }
791+ // FIXME: This adds extra clauses, instead of modifying existing bounds
792+ // Smh. make clean_preds add those bounds onto existing ones if available
793+ // NOTE: Maybe we should just cave in an add an `Option<ty::Generics>` param to clean_preds
794+ // FIXME: This is so stupid
795+ for param in & generics. own_params {
796+ if let ty:: GenericParamDefKind :: Type { synthetic : false , .. } = param. kind
797+ && !cleaner. sized . contains ( & param. index )
798+ {
799+ // FIXME: is this correct if we have parent generics?
800+ where_predicates. push ( WherePredicate :: BoundPredicate {
801+ ty : Type :: Generic ( param. name ) ,
802+ bounds : vec ! [ GenericBound :: maybe_sized( cx) ] ,
803+ bound_params : Vec :: new ( ) ,
804+ } )
805+ }
806+ }
793807
794808 Generics { params, where_predicates }
795809}
@@ -2160,20 +2174,23 @@ fn clean_middle_opaque_bounds<'tcx>(
21602174 // FIXME: we currentyl elide `Sized` bc it looks for bounded_ty=`ty::Param` but we don't
21612175 // care about that here bc we want to look for bounded_ty=Alias(Opaque) (which we can
21622176 // actually assume / don't need to check)
2163- let mut where_predicates = modern:: clean_predicates ( cx, predicates) ;
2164- let Some ( WherePredicate :: BoundPredicate { mut bounds, .. } ) = where_predicates. pop ( ) else {
2165- unreachable ! ( )
2177+ // FIXME: Make it so clean_pred inserts `Sized` before any outlives bounds
2178+ let mut where_predicates =
2179+ modern:: clean_predicates ( cx, predicates, & mut modern:: OpaqueTy :: default ( ) ) ;
2180+ let mut bounds = match where_predicates. pop ( ) {
2181+ Some ( WherePredicate :: BoundPredicate { bounds, .. } ) => bounds,
2182+ Some ( _) => unreachable ! ( ) ,
2183+ None => Vec :: new ( ) ,
21662184 } ;
21672185
21682186 // FIXME: rewrite this, too
21692187 // <LEGACY>
21702188
2171- // Move trait bounds to the front.
2172- bounds. sort_by_key ( |b| !b. is_trait_bound ( ) ) ;
2189+ // // Move trait bounds to the front.
2190+ // bounds.sort_by_key(|b| !b.is_trait_bound());
21732191
21742192 // Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
2175- // Since all potential trait bounds are at the front we can just check the first bound.
2176- if bounds. first ( ) . map_or ( true , |b| !b. is_trait_bound ( ) ) {
2193+ if bounds. iter ( ) . all ( |bound| !bound. is_trait_bound ( ) ) {
21772194 bounds. insert ( 0 , GenericBound :: sized ( cx) ) ;
21782195 }
21792196
0 commit comments