@@ -770,26 +770,40 @@ fn clean_ty_generics<'tcx>(
770
770
// FIXME: does this handle Sized/?Sized properly?
771
771
for ( index, predicates) in apits {
772
772
// 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 ( ) ,
776
779
} ;
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
+ }
777
785
cx. impl_trait_bounds . insert ( index. into ( ) , bounds) ;
778
786
}
779
787
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) ;
781
790
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
+ }
793
807
794
808
Generics { params, where_predicates }
795
809
}
@@ -2160,20 +2174,23 @@ fn clean_middle_opaque_bounds<'tcx>(
2160
2174
// FIXME: we currentyl elide `Sized` bc it looks for bounded_ty=`ty::Param` but we don't
2161
2175
// care about that here bc we want to look for bounded_ty=Alias(Opaque) (which we can
2162
2176
// 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 ( ) ,
2166
2184
} ;
2167
2185
2168
2186
// FIXME: rewrite this, too
2169
2187
// <LEGACY>
2170
2188
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());
2173
2191
2174
2192
// 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 ( ) ) {
2177
2194
bounds. insert ( 0 , GenericBound :: sized ( cx) ) ;
2178
2195
}
2179
2196
0 commit comments