@@ -42,7 +42,7 @@ fn sized_constraint_for_ty<'tcx>(
42
42
let adt_tys = adt. sized_constraint ( tcx) ;
43
43
debug ! ( "sized_constraint_for_ty({:?}) intermediate = {:?}" , ty, adt_tys) ;
44
44
adt_tys
45
- . iter_instantiated_copied ( tcx, args)
45
+ . iter_instantiated ( tcx, args)
46
46
. flat_map ( |ty| sized_constraint_for_ty ( tcx, adtdef, ty) )
47
47
. collect ( )
48
48
}
@@ -58,11 +58,18 @@ fn sized_constraint_for_ty<'tcx>(
58
58
// we know that `T` is Sized and do not need to check
59
59
// it on the impl.
60
60
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] } ;
64
62
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
+ }
66
73
}
67
74
68
75
Placeholder ( ..) | Bound ( ..) | Infer ( ..) => {
@@ -92,10 +99,13 @@ fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
92
99
/// - a tuple of type parameters or projections, if there are multiple
93
100
/// such.
94
101
/// - 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 > > > {
96
106
if let Some ( def_id) = def_id. as_local ( ) {
97
107
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) ] ) ) ;
99
109
}
100
110
}
101
111
let def = tcx. adt_def ( def_id) ;
@@ -107,7 +117,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
107
117
108
118
debug ! ( "adt_sized_constraint: {:?} => {:?}" , def, result) ;
109
119
110
- result
120
+ ty :: EarlyBinder :: bind ( result)
111
121
}
112
122
113
123
/// See `ParamEnv` struct definition for details.
0 commit comments