@@ -777,26 +777,40 @@ fn clean_ty_generics<'tcx>(
777
777
// FIXME: does this handle Sized/?Sized properly?
778
778
for ( index, predicates) in apits {
779
779
// FIXME: fix up API of clean_pred instead
780
- let mut where_predicates = modern:: clean_predicates ( cx, predicates) ;
781
- let Some ( WherePredicate :: BoundPredicate { bounds, .. } ) = where_predicates. pop ( ) else {
782
- unreachable ! ( )
780
+ let mut where_predicates =
781
+ modern:: clean_predicates ( cx, predicates, & mut modern:: Apit :: default ( ) ) ;
782
+ let mut bounds = match where_predicates. pop ( ) {
783
+ Some ( WherePredicate :: BoundPredicate { bounds, .. } ) => bounds,
784
+ Some ( _) => unreachable ! ( ) ,
785
+ None => Vec :: new ( ) ,
783
786
} ;
787
+
788
+ // Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
789
+ if bounds. iter ( ) . all ( |bound| !bound. is_trait_bound ( ) ) {
790
+ bounds. insert ( 0 , GenericBound :: sized ( cx) ) ;
791
+ }
784
792
cx. impl_trait_bounds . insert ( index. into ( ) , bounds) ;
785
793
}
786
794
787
- let where_predicates = modern:: clean_predicates ( cx, predicates) ;
795
+ let mut cleaner = modern:: WhereClause :: default ( ) ;
796
+ let mut where_predicates = modern:: clean_predicates ( cx, predicates, & mut cleaner) ;
788
797
789
- // FIXME: we no longer have access to `sized: UnordMap`
790
- // for param in &generics.own_params {
791
- // if !sized.contains(¶m.index) {
792
- // // FIXME: is this correct if we have parent generics?
793
- // where_predicates.push(WherePredicate::BoundPredicate {
794
- // ty: Type::Generic(param.name),
795
- // bounds: vec![GenericBound::maybe_sized(cx)],
796
- // bound_params: Vec::new(),
797
- // })
798
- // }
799
- // }
798
+ // FIXME: This adds extra clauses, instead of modifying existing bounds
799
+ // Smh. make clean_preds add those bounds onto existing ones if available
800
+ // NOTE: Maybe we should just cave in an add an `Option<ty::Generics>` param to clean_preds
801
+ // FIXME: This is so stupid
802
+ for param in & generics. own_params {
803
+ if let ty:: GenericParamDefKind :: Type { synthetic : false , .. } = param. kind
804
+ && !cleaner. sized . contains ( & param. index )
805
+ {
806
+ // FIXME: is this correct if we have parent generics?
807
+ where_predicates. push ( WherePredicate :: BoundPredicate {
808
+ ty : Type :: Generic ( param. name ) ,
809
+ bounds : vec ! [ GenericBound :: maybe_sized( cx) ] ,
810
+ bound_params : Vec :: new ( ) ,
811
+ } )
812
+ }
813
+ }
800
814
801
815
Generics { params, where_predicates }
802
816
}
@@ -2165,20 +2179,23 @@ fn clean_middle_opaque_bounds<'tcx>(
2165
2179
// FIXME: we currentyl elide `Sized` bc it looks for bounded_ty=`ty::Param` but we don't
2166
2180
// care about that here bc we want to look for bounded_ty=Alias(Opaque) (which we can
2167
2181
// actually assume / don't need to check)
2168
- let mut where_predicates = modern:: clean_predicates ( cx, predicates) ;
2169
- let Some ( WherePredicate :: BoundPredicate { mut bounds, .. } ) = where_predicates. pop ( ) else {
2170
- unreachable ! ( )
2182
+ // FIXME: Make it so clean_pred inserts `Sized` before any outlives bounds
2183
+ let mut where_predicates =
2184
+ modern:: clean_predicates ( cx, predicates, & mut modern:: OpaqueTy :: default ( ) ) ;
2185
+ let mut bounds = match where_predicates. pop ( ) {
2186
+ Some ( WherePredicate :: BoundPredicate { bounds, .. } ) => bounds,
2187
+ Some ( _) => unreachable ! ( ) ,
2188
+ None => Vec :: new ( ) ,
2171
2189
} ;
2172
2190
2173
2191
// FIXME: rewrite this, too
2174
2192
// <LEGACY>
2175
2193
2176
- // Move trait bounds to the front.
2177
- bounds. sort_by_key ( |b| !b. is_trait_bound ( ) ) ;
2194
+ // // Move trait bounds to the front.
2195
+ // bounds.sort_by_key(|b| !b.is_trait_bound());
2178
2196
2179
2197
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
2180
- // Since all potential trait bounds are at the front we can just check the first bound.
2181
- if bounds. first ( ) . map_or ( true , |b| !b. is_trait_bound ( ) ) {
2198
+ if bounds. iter ( ) . all ( |bound| !bound. is_trait_bound ( ) ) {
2182
2199
bounds. insert ( 0 , GenericBound :: sized ( cx) ) ;
2183
2200
}
2184
2201
0 commit comments