@@ -42,7 +42,7 @@ fn sized_constraint_for_ty<'tcx>(
4242 let adt_tys = adt. sized_constraint ( tcx) ;
4343 debug ! ( "sized_constraint_for_ty({:?}) intermediate = {:?}" , ty, adt_tys) ;
4444 adt_tys
45- . iter_instantiated_copied ( tcx, args)
45+ . iter_instantiated ( tcx, args)
4646 . flat_map ( |ty| sized_constraint_for_ty ( tcx, adtdef, ty) )
4747 . collect ( )
4848 }
@@ -58,11 +58,18 @@ fn sized_constraint_for_ty<'tcx>(
5858 // we know that `T` is Sized and do not need to check
5959 // it on the impl.
6060
61- let Some ( sized_trait) = tcx. lang_items ( ) . sized_trait ( ) else { return vec ! [ ty] } ;
62- let sized_predicate =
63- ty:: TraitRef :: new ( tcx, sized_trait, [ ty] ) . without_const ( ) . to_predicate ( tcx) ;
61+ let Some ( sized_trait_def_id) = tcx. lang_items ( ) . sized_trait ( ) else { return vec ! [ ty] } ;
6462 let predicates = tcx. predicates_of ( adtdef. did ( ) ) . predicates ;
65- if predicates. iter ( ) . any ( |( p, _) | * p == sized_predicate) { vec ! [ ] } else { vec ! [ ty] }
63+ if predicates. iter ( ) . any ( |( p, _) | {
64+ p. as_trait_clause ( ) . is_some_and ( |trait_pred| {
65+ trait_pred. def_id ( ) == sized_trait_def_id
66+ && trait_pred. self_ty ( ) . skip_binder ( ) == ty
67+ } )
68+ } ) {
69+ vec ! [ ]
70+ } else {
71+ vec ! [ ty]
72+ }
6673 }
6774
6875 Placeholder ( ..) | Bound ( ..) | Infer ( ..) => {
@@ -92,10 +99,13 @@ fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
9299/// - a tuple of type parameters or projections, if there are multiple
93100/// such.
94101/// - an Error, if a type is infinitely sized
95- fn adt_sized_constraint ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> & [ Ty < ' _ > ] {
102+ fn adt_sized_constraint < ' tcx > (
103+ tcx : TyCtxt < ' tcx > ,
104+ def_id : DefId ,
105+ ) -> ty:: EarlyBinder < & ' tcx ty:: List < Ty < ' tcx > > > {
96106 if let Some ( def_id) = def_id. as_local ( ) {
97107 if matches ! ( tcx. representability( def_id) , ty:: Representability :: Infinite ) {
98- return tcx. mk_type_list ( & [ Ty :: new_misc_error ( tcx) ] ) ;
108+ return ty :: EarlyBinder :: bind ( tcx. mk_type_list ( & [ Ty :: new_misc_error ( tcx) ] ) ) ;
99109 }
100110 }
101111 let def = tcx. adt_def ( def_id) ;
@@ -107,7 +117,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
107117
108118 debug ! ( "adt_sized_constraint: {:?} => {:?}" , def, result) ;
109119
110- result
120+ ty :: EarlyBinder :: bind ( result)
111121}
112122
113123/// See `ParamEnv` struct definition for details.
0 commit comments