@@ -18,7 +18,7 @@ use crate::solve::{AdtDestructorKind, EvalCtxt, Goal, NoSolution};
18
18
pub ( in crate :: solve) fn instantiate_constituent_tys_for_auto_trait < D , I > (
19
19
ecx : & EvalCtxt < ' _ , D > ,
20
20
ty : I :: Ty ,
21
- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
21
+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
22
22
where
23
23
D : SolverDelegate < Interner = I > ,
24
24
I : Interner ,
@@ -33,10 +33,10 @@ where
33
33
| ty:: FnPtr ( ..)
34
34
| ty:: Error ( _)
35
35
| ty:: Never
36
- | ty:: Char => Ok ( vec ! [ ] ) ,
36
+ | ty:: Char => Ok ( ty :: Binder :: dummy ( vec ! [ ] ) ) ,
37
37
38
38
// 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) ) ] ) ) ,
40
40
41
41
ty:: Dynamic ( ..)
42
42
| ty:: Param ( ..)
@@ -49,53 +49,49 @@ where
49
49
}
50
50
51
51
ty:: RawPtr ( element_ty, _) | ty:: Ref ( _, element_ty, _) => {
52
- Ok ( vec ! [ ty:: Binder :: dummy( element_ty) ] )
52
+ Ok ( ty:: Binder :: dummy ( vec ! [ element_ty] ) )
53
53
}
54
54
55
55
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] ) )
57
57
}
58
58
59
59
ty:: Tuple ( tys) => {
60
60
// (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 ( ) ) )
62
62
}
63
63
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( ) ] ) ) ,
65
65
66
66
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( ) ] ) )
68
68
}
69
69
70
70
ty:: Coroutine ( _, args) => {
71
71
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( ) ] ) )
76
73
}
77
74
78
75
ty:: CoroutineWitness ( def_id, args) => Ok ( ecx
79
76
. 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 ( ) ) ) ,
84
80
85
- ty:: UnsafeBinder ( bound_ty) => Ok ( vec ! [ bound_ty. into ( ) ] ) ,
81
+ ty:: UnsafeBinder ( bound_ty) => Ok ( bound_ty. map_bound ( |ty| vec ! [ ty ] ) ) ,
86
82
87
83
// 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 ) ] ) ) ,
89
85
90
86
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 ( ) ) )
92
88
}
93
89
94
90
ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => {
95
91
// We can resolve the `impl Trait` to its concrete type,
96
92
// which enforces a DAG between the functions requiring
97
93
// 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) ] ) )
99
95
}
100
96
}
101
97
}
@@ -104,7 +100,7 @@ where
104
100
pub ( in crate :: solve) fn instantiate_constituent_tys_for_sized_trait < D , I > (
105
101
ecx : & EvalCtxt < ' _ , D > ,
106
102
ty : I :: Ty ,
107
- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
103
+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
108
104
where
109
105
D : SolverDelegate < Interner = I > ,
110
106
I : Interner ,
@@ -130,7 +126,7 @@ where
130
126
| ty:: CoroutineClosure ( ..)
131
127
| ty:: Never
132
128
| ty:: Dynamic ( _, _, ty:: DynStar )
133
- | ty:: Error ( _) => Ok ( vec ! [ ] ) ,
129
+ | ty:: Error ( _) => Ok ( ty :: Binder :: dummy ( vec ! [ ] ) ) ,
134
130
135
131
ty:: Str
136
132
| ty:: Slice ( _)
@@ -145,11 +141,11 @@ where
145
141
panic ! ( "unexpected type `{ty:?}`" )
146
142
}
147
143
148
- ty:: UnsafeBinder ( bound_ty) => Ok ( vec ! [ bound_ty. into ( ) ] ) ,
144
+ ty:: UnsafeBinder ( bound_ty) => Ok ( bound_ty. map_bound ( |ty| vec ! [ ty ] ) ) ,
149
145
150
146
// impl Sized for ()
151
147
// 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] ) ) ) ,
153
149
154
150
// impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
155
151
// `sized_constraint(Adt)` is the deepest struct trail that can be determined
@@ -162,9 +158,9 @@ where
162
158
// if the ADT is sized for all possible args.
163
159
ty:: Adt ( def, args) => {
164
160
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) ] ) )
166
162
} else {
167
- Ok ( vec ! [ ] )
163
+ Ok ( ty :: Binder :: dummy ( vec ! [ ] ) )
168
164
}
169
165
}
170
166
}
@@ -174,14 +170,14 @@ where
174
170
pub ( in crate :: solve) fn instantiate_constituent_tys_for_copy_clone_trait < D , I > (
175
171
ecx : & EvalCtxt < ' _ , D > ,
176
172
ty : I :: Ty ,
177
- ) -> Result < Vec < ty:: Binder < I , I :: Ty > > , NoSolution >
173
+ ) -> Result < ty:: Binder < I , Vec < I :: Ty > > , NoSolution >
178
174
where
179
175
D : SolverDelegate < Interner = I > ,
180
176
I : Interner ,
181
177
{
182
178
match ty. kind ( ) {
183
179
// 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 ! [ ] ) ) ,
185
181
186
182
// Implementations are provided in core
187
183
ty:: Uint ( _)
@@ -197,7 +193,7 @@ where
197
193
198
194
// Cannot implement in core, as we can't be generic over patterns yet,
199
195
// 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 ] ) ) ,
201
197
202
198
ty:: Dynamic ( ..)
203
199
| ty:: Str
@@ -215,14 +211,14 @@ where
215
211
}
216
212
217
213
// 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 ( ) ) ) ,
219
215
220
216
// 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( ) ] ) ) ,
222
218
223
219
// impl Copy/Clone for CoroutineClosure where Self::TupledUpvars: Copy/Clone
224
220
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( ) ] ) )
226
222
}
227
223
228
224
// only when `coroutine_clone` is enabled and the coroutine is movable
@@ -232,10 +228,7 @@ where
232
228
Movability :: Movable => {
233
229
if ecx. cx ( ) . features ( ) . coroutine_clone ( ) {
234
230
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( ) ] ) )
239
232
} else {
240
233
Err ( NoSolution )
241
234
}
@@ -247,10 +240,9 @@ where
247
240
// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
248
241
ty:: CoroutineWitness ( def_id, args) => Ok ( ecx
249
242
. 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 ( ) ) ) ,
254
246
}
255
247
}
256
248
0 commit comments