@@ -5,6 +5,7 @@ use derive_where::derive_where;
55use rustc_type_ir:: data_structures:: HashMap ;
66use rustc_type_ir:: inherent:: * ;
77use rustc_type_ir:: lang_items:: TraitSolverLangItem ;
8+ use rustc_type_ir:: solve:: SizedTraitKind ;
89use rustc_type_ir:: solve:: inspect:: ProbeKind ;
910use rustc_type_ir:: {
1011 self as ty, FallibleTypeFolder , Interner , Movability , Mutability , TypeFoldable ,
@@ -104,17 +105,19 @@ where
104105}
105106
106107#[ instrument( level = "trace" , skip( ecx) , ret) ]
107- pub ( in crate :: solve) fn instantiate_constituent_tys_for_sized_trait < D , I > (
108+ pub ( in crate :: solve) fn instantiate_constituent_tys_for_sizedness_trait < D , I > (
108109 ecx : & EvalCtxt < ' _ , D > ,
110+ sizedness : SizedTraitKind ,
109111 ty : I :: Ty ,
110112) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
111113where
112114 D : SolverDelegate < Interner = I > ,
113115 I : Interner ,
114116{
115117 match ty. kind ( ) {
116- // impl Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
117- // impl Sized for Coroutine, CoroutineWitness, Closure, CoroutineClosure
118+ // impl {Meta,}Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char
119+ // impl {Meta,}Sized for &mut? T, [T; N], dyn* Trait, !, Coroutine, CoroutineWitness
120+ // impl {Meta,}Sized for Closure, CoroutineClosure
118121 ty:: Infer ( ty:: IntVar ( _) | ty:: FloatVar ( _) )
119122 | ty:: Uint ( _)
120123 | ty:: Int ( _)
@@ -135,13 +138,16 @@ where
135138 | ty:: Dynamic ( _, _, ty:: DynStar )
136139 | ty:: Error ( _) => Ok ( ty:: Binder :: dummy ( vec ! [ ] ) ) ,
137140
138- ty:: Str
139- | ty:: Slice ( _)
140- | ty:: Dynamic ( ..)
141- | ty:: Foreign ( ..)
142- | ty:: Alias ( ..)
143- | ty:: Param ( _)
144- | ty:: Placeholder ( ..) => Err ( NoSolution ) ,
141+ // impl {Meta,}Sized for str, [T], dyn Trait
142+ ty:: Str | ty:: Slice ( _) | ty:: Dynamic ( ..) => match sizedness {
143+ SizedTraitKind :: Sized => Err ( NoSolution ) ,
144+ SizedTraitKind :: MetaSized => Ok ( ty:: Binder :: dummy ( vec ! [ ] ) ) ,
145+ } ,
146+
147+ // impl {} for extern type
148+ ty:: Foreign ( ..) => Err ( NoSolution ) ,
149+
150+ ty:: Alias ( ..) | ty:: Param ( _) | ty:: Placeholder ( ..) => Err ( NoSolution ) ,
145151
146152 ty:: Bound ( ..)
147153 | ty:: Infer ( ty:: TyVar ( _) | ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
@@ -150,22 +156,27 @@ where
150156
151157 ty:: UnsafeBinder ( bound_ty) => Ok ( bound_ty. map_bound ( |ty| vec ! [ ty] ) ) ,
152158
153- // impl Sized for ()
154- // impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
159+ // impl {Meta,} Sized for ()
160+ // impl {Meta,} Sized for (T1, T2, .., Tn) where Tn: {Meta,} Sized if n >= 1
155161 ty:: Tuple ( tys) => Ok ( ty:: Binder :: dummy ( tys. last ( ) . map_or_else ( Vec :: new, |ty| vec ! [ ty] ) ) ) ,
156162
157- // impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
158- // `sized_constraint(Adt)` is the deepest struct trail that can be determined
159- // by the definition of `Adt`, independent of the generic args.
160- // impl Sized for Adt<Args...> if sized_constraint(Adt) == None
161- // As a performance optimization, `sized_constraint(Adt)` can return `None`
162- // if the ADTs definition implies that it is sized by for all possible args.
163+ // impl {Meta,}Sized for Adt<Args...>
164+ // where {meta,pointee,}sized_constraint(Adt)<Args...>: {Meta,}Sized
165+ //
166+ // `{meta,pointee,}sized_constraint(Adt)` is the deepest struct trail that can be
167+ // determined by the definition of `Adt`, independent of the generic args.
168+ //
169+ // impl {Meta,}Sized for Adt<Args...>
170+ // if {meta,pointee,}sized_constraint(Adt) == None
171+ //
172+ // As a performance optimization, `{meta,pointee,}sized_constraint(Adt)` can return `None`
173+ // if the ADTs definition implies that it is {meta,}sized by for all possible args.
163174 // In this case, the builtin impl will have no nested subgoals. This is a
164- // "best effort" optimization and `sized_constraint` may return `Some`, even
165- // if the ADT is sized for all possible args.
175+ // "best effort" optimization and `{meta,pointee,} sized_constraint` may return `Some`,
176+ // even if the ADT is {meta,pointee,} sized for all possible args.
166177 ty:: Adt ( def, args) => {
167- if let Some ( sized_crit ) = def. sized_constraint ( ecx. cx ( ) ) {
168- Ok ( ty:: Binder :: dummy ( vec ! [ sized_crit . instantiate( ecx. cx( ) , args) ] ) )
178+ if let Some ( crit ) = def. sizedness_constraint ( ecx. cx ( ) , sizedness ) {
179+ Ok ( ty:: Binder :: dummy ( vec ! [ crit . instantiate( ecx. cx( ) , args) ] ) )
169180 } else {
170181 Ok ( ty:: Binder :: dummy ( vec ! [ ] ) )
171182 }
0 commit comments