@@ -18,7 +18,7 @@ use crate::solve::{AdtDestructorKind, EvalCtxt, Goal, NoSolution};
1818pub ( in crate :: solve) fn instantiate_constituent_tys_for_auto_trait < D , I > (
1919 ecx : & EvalCtxt < ' _ , D > ,
2020 ty : I :: Ty ,
21- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
21+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
2222where
2323 D : SolverDelegate < Interner = I > ,
2424 I : Interner ,
@@ -33,10 +33,10 @@ where
3333 | ty:: FnPtr ( ..)
3434 | ty:: Error ( _)
3535 | ty:: Never
36- | ty:: Char => Ok ( vec ! [ ] ) ,
36+ | ty:: Char => Ok ( ty :: Binder :: dummy ( vec ! [ ] ) ) ,
3737
3838 // Treat `str` like it's defined as `struct str([u8]);`
39- ty:: Str => Ok ( vec ! [ ty:: Binder :: dummy( Ty :: new_slice( cx, Ty :: new_u8( cx) ) ) ] ) ,
39+ ty:: Str => Ok ( ty:: Binder :: dummy ( vec ! [ Ty :: new_slice( cx, Ty :: new_u8( cx) ) ] ) ) ,
4040
4141 ty:: Dynamic ( ..)
4242 | ty:: Param ( ..)
@@ -49,53 +49,49 @@ where
4949 }
5050
5151 ty:: RawPtr ( element_ty, _) | ty:: Ref ( _, element_ty, _) => {
52- Ok ( vec ! [ ty:: Binder :: dummy( element_ty) ] )
52+ Ok ( ty:: Binder :: dummy ( vec ! [ element_ty] ) )
5353 }
5454
5555 ty:: Pat ( element_ty, _) | ty:: Array ( element_ty, _) | ty:: Slice ( element_ty) => {
56- Ok ( vec ! [ ty:: Binder :: dummy( element_ty) ] )
56+ Ok ( ty:: Binder :: dummy ( vec ! [ element_ty] ) )
5757 }
5858
5959 ty:: Tuple ( tys) => {
6060 // (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
61- Ok ( tys . iter ( ) . map ( ty:: Binder :: dummy) . collect ( ) )
61+ Ok ( ty:: Binder :: dummy ( tys . to_vec ( ) ) )
6262 }
6363
64- ty:: Closure ( _, args) => Ok ( vec ! [ ty:: Binder :: dummy( args. as_closure( ) . tupled_upvars_ty( ) ) ] ) ,
64+ ty:: Closure ( _, args) => Ok ( ty:: Binder :: dummy ( vec ! [ args. as_closure( ) . tupled_upvars_ty( ) ] ) ) ,
6565
6666 ty:: CoroutineClosure ( _, args) => {
67- Ok ( vec ! [ ty:: Binder :: dummy( args. as_coroutine_closure( ) . tupled_upvars_ty( ) ) ] )
67+ Ok ( ty:: Binder :: dummy ( vec ! [ args. as_coroutine_closure( ) . tupled_upvars_ty( ) ] ) )
6868 }
6969
7070 ty:: Coroutine ( _, args) => {
7171 let coroutine_args = args. as_coroutine ( ) ;
72- Ok ( vec ! [
73- ty:: Binder :: dummy( coroutine_args. tupled_upvars_ty( ) ) ,
74- ty:: Binder :: dummy( coroutine_args. witness( ) ) ,
75- ] )
72+ Ok ( ty:: Binder :: dummy ( vec ! [ coroutine_args. tupled_upvars_ty( ) , coroutine_args. witness( ) ] ) )
7673 }
7774
7875 ty:: CoroutineWitness ( def_id, args) => Ok ( ecx
7976 . cx ( )
80- . bound_coroutine_hidden_types ( def_id)
81- . into_iter ( )
82- . map ( |bty| bty. instantiate ( cx, args) )
83- . collect ( ) ) ,
77+ . coroutine_hidden_types ( def_id)
78+ . instantiate ( cx, args)
79+ . map_bound ( |tys| tys. to_vec ( ) ) ) ,
8480
85- ty:: UnsafeBinder ( bound_ty) => Ok ( vec ! [ bound_ty. into ( ) ] ) ,
81+ ty:: UnsafeBinder ( bound_ty) => Ok ( bound_ty. map_bound ( |ty| vec ! [ ty ] ) ) ,
8682
8783 // For `PhantomData<T>`, we pass `T`.
88- ty:: Adt ( def, args) if def. is_phantom_data ( ) => Ok ( vec ! [ ty:: Binder :: dummy( args. type_at( 0 ) ) ] ) ,
84+ ty:: Adt ( def, args) if def. is_phantom_data ( ) => Ok ( ty:: Binder :: dummy ( vec ! [ args. type_at( 0 ) ] ) ) ,
8985
9086 ty:: Adt ( def, args) => {
91- Ok ( def. all_field_tys ( cx) . iter_instantiated ( cx, args) . map ( ty :: Binder :: dummy ) . collect ( ) )
87+ Ok ( ty :: Binder :: dummy ( def. all_field_tys ( cx) . iter_instantiated ( cx, args) . collect ( ) ) )
9288 }
9389
9490 ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => {
9591 // We can resolve the `impl Trait` to its concrete type,
9692 // which enforces a DAG between the functions requiring
9793 // the auto trait bounds in question.
98- Ok ( vec ! [ ty:: Binder :: dummy( cx. type_of( def_id) . instantiate( cx, args) ) ] )
94+ Ok ( ty:: Binder :: dummy ( vec ! [ cx. type_of( def_id) . instantiate( cx, args) ] ) )
9995 }
10096 }
10197}
@@ -104,7 +100,7 @@ where
104100pub ( in crate :: solve) fn instantiate_constituent_tys_for_sized_trait < D , I > (
105101 ecx : & EvalCtxt < ' _ , D > ,
106102 ty : I :: Ty ,
107- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
103+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
108104where
109105 D : SolverDelegate < Interner = I > ,
110106 I : Interner ,
@@ -130,7 +126,7 @@ where
130126 | ty:: CoroutineClosure ( ..)
131127 | ty:: Never
132128 | ty:: Dynamic ( _, _, ty:: DynStar )
133- | ty:: Error ( _) => Ok ( vec ! [ ] ) ,
129+ | ty:: Error ( _) => Ok ( ty :: Binder :: dummy ( vec ! [ ] ) ) ,
134130
135131 ty:: Str
136132 | ty:: Slice ( _)
@@ -145,11 +141,11 @@ where
145141 panic ! ( "unexpected type `{ty:?}`" )
146142 }
147143
148- ty:: UnsafeBinder ( bound_ty) => Ok ( vec ! [ bound_ty. into ( ) ] ) ,
144+ ty:: UnsafeBinder ( bound_ty) => Ok ( bound_ty. map_bound ( |ty| vec ! [ ty ] ) ) ,
149145
150146 // impl Sized for ()
151147 // impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
152- ty:: Tuple ( tys) => Ok ( tys. last ( ) . map_or_else ( Vec :: new, |ty| vec ! [ ty:: Binder :: dummy ( ty ) ] ) ) ,
148+ ty:: Tuple ( tys) => Ok ( ty :: Binder :: dummy ( tys. last ( ) . map_or_else ( Vec :: new, |ty| vec ! [ ty] ) ) ) ,
153149
154150 // impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
155151 // `sized_constraint(Adt)` is the deepest struct trail that can be determined
@@ -162,9 +158,9 @@ where
162158 // if the ADT is sized for all possible args.
163159 ty:: Adt ( def, args) => {
164160 if let Some ( sized_crit) = def. sized_constraint ( ecx. cx ( ) ) {
165- Ok ( vec ! [ ty:: Binder :: dummy( sized_crit. instantiate( ecx. cx( ) , args) ) ] )
161+ Ok ( ty:: Binder :: dummy ( vec ! [ sized_crit. instantiate( ecx. cx( ) , args) ] ) )
166162 } else {
167- Ok ( vec ! [ ] )
163+ Ok ( ty :: Binder :: dummy ( vec ! [ ] ) )
168164 }
169165 }
170166 }
@@ -174,14 +170,14 @@ where
174170pub ( in crate :: solve) fn instantiate_constituent_tys_for_copy_clone_trait < D , I > (
175171 ecx : & EvalCtxt < ' _ , D > ,
176172 ty : I :: Ty ,
177- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
173+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
178174where
179175 D : SolverDelegate < Interner = I > ,
180176 I : Interner ,
181177{
182178 match ty. kind ( ) {
183179 // impl Copy/Clone for FnDef, FnPtr
184- ty:: FnDef ( ..) | ty:: FnPtr ( ..) | ty:: Error ( _) => Ok ( vec ! [ ] ) ,
180+ ty:: FnDef ( ..) | ty:: FnPtr ( ..) | ty:: Error ( _) => Ok ( ty :: Binder :: dummy ( vec ! [ ] ) ) ,
185181
186182 // Implementations are provided in core
187183 ty:: Uint ( _)
@@ -197,7 +193,7 @@ where
197193
198194 // Cannot implement in core, as we can't be generic over patterns yet,
199195 // so we'd have to list all patterns and type combinations.
200- ty:: Pat ( ty, ..) => Ok ( vec ! [ ty:: Binder :: dummy( ty ) ] ) ,
196+ ty:: Pat ( ty, ..) => Ok ( ty:: Binder :: dummy ( vec ! [ ty ] ) ) ,
201197
202198 ty:: Dynamic ( ..)
203199 | ty:: Str
@@ -215,14 +211,14 @@ where
215211 }
216212
217213 // impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
218- ty:: Tuple ( tys) => Ok ( tys . iter ( ) . map ( ty:: Binder :: dummy) . collect ( ) ) ,
214+ ty:: Tuple ( tys) => Ok ( ty:: Binder :: dummy ( tys . to_vec ( ) ) ) ,
219215
220216 // impl Copy/Clone for Closure where Self::TupledUpvars: Copy/Clone
221- ty:: Closure ( _, args) => Ok ( vec ! [ ty:: Binder :: dummy( args. as_closure( ) . tupled_upvars_ty( ) ) ] ) ,
217+ ty:: Closure ( _, args) => Ok ( ty:: Binder :: dummy ( vec ! [ args. as_closure( ) . tupled_upvars_ty( ) ] ) ) ,
222218
223219 // impl Copy/Clone for CoroutineClosure where Self::TupledUpvars: Copy/Clone
224220 ty:: CoroutineClosure ( _, args) => {
225- Ok ( vec ! [ ty:: Binder :: dummy( args. as_coroutine_closure( ) . tupled_upvars_ty( ) ) ] )
221+ Ok ( ty:: Binder :: dummy ( vec ! [ args. as_coroutine_closure( ) . tupled_upvars_ty( ) ] ) )
226222 }
227223
228224 // only when `coroutine_clone` is enabled and the coroutine is movable
@@ -232,10 +228,7 @@ where
232228 Movability :: Movable => {
233229 if ecx. cx ( ) . features ( ) . coroutine_clone ( ) {
234230 let coroutine = args. as_coroutine ( ) ;
235- Ok ( vec ! [
236- ty:: Binder :: dummy( coroutine. tupled_upvars_ty( ) ) ,
237- ty:: Binder :: dummy( coroutine. witness( ) ) ,
238- ] )
231+ Ok ( ty:: Binder :: dummy ( vec ! [ coroutine. tupled_upvars_ty( ) , coroutine. witness( ) ] ) )
239232 } else {
240233 Err ( NoSolution )
241234 }
@@ -247,10 +240,9 @@ where
247240 // impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
248241 ty:: CoroutineWitness ( def_id, args) => Ok ( ecx
249242 . cx ( )
250- . bound_coroutine_hidden_types ( def_id)
251- . into_iter ( )
252- . map ( |bty| bty. instantiate ( ecx. cx ( ) , args) )
253- . collect ( ) ) ,
243+ . coroutine_hidden_types ( def_id)
244+ . instantiate ( ecx. cx ( ) , args)
245+ . map_bound ( |tys| tys. to_vec ( ) ) ) ,
254246 }
255247}
256248
0 commit comments