@@ -149,9 +149,9 @@ impl SimplifiedType {
149
149
}
150
150
}
151
151
152
- /// Given generic arguments from an obligation and an impl ,
153
- /// could these two be unified after replacing parameters in the
154
- /// the impl with inference variables.
152
+ /// Given generic arguments from an obligation and a candidate ,
153
+ /// could these two be unified after replacing parameters and bound
154
+ /// variables in the candidate with inference variables.
155
155
///
156
156
/// For obligations, parameters won't be replaced by inference
157
157
/// variables and only unify with themselves. We treat them
@@ -170,28 +170,30 @@ impl DeepRejectCtxt {
170
170
pub fn args_may_unify < ' tcx > (
171
171
self ,
172
172
obligation_args : GenericArgsRef < ' tcx > ,
173
- impl_args : GenericArgsRef < ' tcx > ,
173
+ candidate_args : GenericArgsRef < ' tcx > ,
174
174
) -> bool {
175
- iter:: zip ( obligation_args, impl_args ) . all ( |( obl, imp) | {
175
+ iter:: zip ( obligation_args, candidate_args ) . all ( |( obl, imp) | {
176
176
match ( obl. unpack ( ) , imp. unpack ( ) ) {
177
177
// We don't fast reject based on regions.
178
178
( GenericArgKind :: Lifetime ( _) , GenericArgKind :: Lifetime ( _) ) => true ,
179
- ( GenericArgKind :: Type ( obl) , GenericArgKind :: Type ( imp ) ) => {
180
- self . types_may_unify ( obl, imp )
179
+ ( GenericArgKind :: Type ( obl) , GenericArgKind :: Type ( candidate ) ) => {
180
+ self . types_may_unify ( obl, candidate )
181
181
}
182
- ( GenericArgKind :: Const ( obl) , GenericArgKind :: Const ( imp ) ) => {
183
- self . consts_may_unify ( obl, imp )
182
+ ( GenericArgKind :: Const ( obl) , GenericArgKind :: Const ( candidate ) ) => {
183
+ self . consts_may_unify ( obl, candidate )
184
184
}
185
185
_ => bug ! ( "kind mismatch: {obl} {imp}" ) ,
186
186
}
187
187
} )
188
188
}
189
189
190
- pub fn types_may_unify < ' tcx > ( self , obligation_ty : Ty < ' tcx > , impl_ty : Ty < ' tcx > ) -> bool {
191
- match impl_ty . kind ( ) {
192
- // Start by checking whether the type in the impl may unify with
190
+ pub fn types_may_unify < ' tcx > ( self , obligation_ty : Ty < ' tcx > , candidate_ty : Ty < ' tcx > ) -> bool {
191
+ match candidate_ty . kind ( ) {
192
+ // Start by checking whether the type in the candidate may unify with
193
193
// pretty much everything. Just return `true` in that case.
194
- ty:: Param ( _) | ty:: Error ( _) | ty:: Alias ( ..) => return true ,
194
+ ty:: Param ( _) | ty:: Error ( _) | ty:: Alias ( ..) | ty:: Infer ( _) | ty:: Placeholder ( ..) => {
195
+ return true ;
196
+ }
195
197
// These types only unify with inference variables or their own
196
198
// variant.
197
199
ty:: Bool
@@ -210,18 +212,15 @@ impl DeepRejectCtxt {
210
212
| ty:: Never
211
213
| ty:: Tuple ( ..)
212
214
| ty:: FnPtr ( ..)
213
- | ty:: Foreign ( ..) => debug_assert ! ( impl_ty . is_known_rigid( ) ) ,
215
+ | ty:: Foreign ( ..) => debug_assert ! ( candidate_ty . is_known_rigid( ) ) ,
214
216
ty:: FnDef ( ..)
215
217
| ty:: Closure ( ..)
216
218
| ty:: CoroutineClosure ( ..)
217
219
| ty:: Coroutine ( ..)
218
220
| ty:: CoroutineWitness ( ..)
219
- | ty:: Placeholder ( ..)
220
- | ty:: Bound ( ..)
221
- | ty:: Infer ( _) => bug ! ( "unexpected impl_ty: {impl_ty}" ) ,
221
+ | ty:: Bound ( ..) => bug ! ( "unexpected candidate_ty: {candidate_ty}" ) ,
222
222
}
223
223
224
- let k = impl_ty. kind ( ) ;
225
224
match * obligation_ty. kind ( ) {
226
225
// Purely rigid types, use structural equivalence.
227
226
ty:: Bool
@@ -231,65 +230,68 @@ impl DeepRejectCtxt {
231
230
| ty:: Float ( _)
232
231
| ty:: Str
233
232
| ty:: Never
234
- | ty:: Foreign ( _) => obligation_ty == impl_ty ,
235
- ty:: Ref ( _, obl_ty, obl_mutbl) => match k {
236
- & ty:: Ref ( _, impl_ty , impl_mutbl ) => {
237
- obl_mutbl == impl_mutbl && self . types_may_unify ( obl_ty, impl_ty )
233
+ | ty:: Foreign ( _) => obligation_ty == candidate_ty ,
234
+ ty:: Ref ( _, obl_ty, obl_mutbl) => match candidate_ty . kind ( ) {
235
+ & ty:: Ref ( _, cand_ty , cand_mutbl ) => {
236
+ obl_mutbl == cand_mutbl && self . types_may_unify ( obl_ty, cand_ty )
238
237
}
239
238
_ => false ,
240
239
} ,
241
- ty:: Adt ( obl_def, obl_args) => match k {
242
- & ty:: Adt ( impl_def , impl_args ) => {
243
- obl_def == impl_def && self . args_may_unify ( obl_args, impl_args )
240
+ ty:: Adt ( obl_def, obl_args) => match candidate_ty . kind ( ) {
241
+ & ty:: Adt ( cand_def , cand_args ) => {
242
+ obl_def == cand_def && self . args_may_unify ( obl_args, cand_args )
244
243
}
245
244
_ => false ,
246
245
} ,
247
- ty:: Pat ( obl_ty, _) => {
246
+ ty:: Pat ( obl_ty, _) => match candidate_ty . kind ( ) {
248
247
// FIXME(pattern_types): take pattern into account
249
- matches ! ( k, & ty:: Pat ( impl_ty, _) if self . types_may_unify( obl_ty, impl_ty) )
250
- }
251
- ty:: Slice ( obl_ty) => {
252
- matches ! ( k, & ty:: Slice ( impl_ty) if self . types_may_unify( obl_ty, impl_ty) )
253
- }
254
- ty:: Array ( obl_ty, obl_len) => match k {
255
- & ty:: Array ( impl_ty, impl_len) => {
256
- self . types_may_unify ( obl_ty, impl_ty)
257
- && self . consts_may_unify ( obl_len, impl_len)
248
+ & ty:: Pat ( cand_ty, _) => self . types_may_unify ( obl_ty, cand_ty) ,
249
+ _ => false ,
250
+ } ,
251
+ ty:: Slice ( obl_ty) => match candidate_ty. kind ( ) {
252
+ & ty:: Slice ( cand_ty) => self . types_may_unify ( obl_ty, cand_ty) ,
253
+ _ => false ,
254
+ } ,
255
+ ty:: Array ( obl_ty, obl_len) => match candidate_ty. kind ( ) {
256
+ & ty:: Array ( cand_ty, cand_len) => {
257
+ self . types_may_unify ( obl_ty, cand_ty)
258
+ && self . consts_may_unify ( obl_len, cand_len)
258
259
}
259
260
_ => false ,
260
261
} ,
261
- ty:: Tuple ( obl) => match k {
262
- & ty:: Tuple ( imp ) => {
263
- obl. len ( ) == imp . len ( )
264
- && iter:: zip ( obl, imp ) . all ( |( obl, imp ) | self . types_may_unify ( obl, imp ) )
262
+ ty:: Tuple ( obl) => match candidate_ty . kind ( ) {
263
+ & ty:: Tuple ( cand ) => {
264
+ obl. len ( ) == cand . len ( )
265
+ && iter:: zip ( obl, cand ) . all ( |( obl, cand ) | self . types_may_unify ( obl, cand ) )
265
266
}
266
267
_ => false ,
267
268
} ,
268
- ty:: RawPtr ( obl_ty, obl_mutbl) => match * k {
269
- ty:: RawPtr ( imp_ty , imp_mutbl ) => {
270
- obl_mutbl == imp_mutbl && self . types_may_unify ( obl_ty, imp_ty )
269
+ ty:: RawPtr ( obl_ty, obl_mutbl) => match * candidate_ty . kind ( ) {
270
+ ty:: RawPtr ( cand_ty , cand_mutbl ) => {
271
+ obl_mutbl == cand_mutbl && self . types_may_unify ( obl_ty, cand_ty )
271
272
}
272
273
_ => false ,
273
274
} ,
274
- ty:: Dynamic ( obl_preds, ..) => {
275
+ ty:: Dynamic ( obl_preds, ..) => match candidate_ty . kind ( ) {
275
276
// Ideally we would walk the existential predicates here or at least
276
277
// compare their length. But considering that the relevant `Relate` impl
277
278
// actually sorts and deduplicates these, that doesn't work.
278
- matches ! ( k, ty:: Dynamic ( impl_preds, ..) if
279
- obl_preds. principal_def_id( ) == impl_preds. principal_def_id( )
280
- )
281
- }
282
- ty:: FnPtr ( obl_sig) => match k {
283
- ty:: FnPtr ( impl_sig) => {
279
+ ty:: Dynamic ( cand_preds, ..) => {
280
+ obl_preds. principal_def_id ( ) == cand_preds. principal_def_id ( )
281
+ }
282
+ _ => false ,
283
+ } ,
284
+ ty:: FnPtr ( obl_sig) => match candidate_ty. kind ( ) {
285
+ ty:: FnPtr ( cand_sig) => {
284
286
let ty:: FnSig { inputs_and_output, c_variadic, safety, abi } =
285
287
obl_sig. skip_binder ( ) ;
286
- let impl_sig = impl_sig . skip_binder ( ) ;
288
+ let cand_sig = cand_sig . skip_binder ( ) ;
287
289
288
- abi == impl_sig . abi
289
- && c_variadic == impl_sig . c_variadic
290
- && safety == impl_sig . safety
291
- && inputs_and_output. len ( ) == impl_sig . inputs_and_output . len ( )
292
- && iter:: zip ( inputs_and_output, impl_sig . inputs_and_output )
290
+ abi == cand_sig . abi
291
+ && c_variadic == cand_sig . c_variadic
292
+ && safety == cand_sig . safety
293
+ && inputs_and_output. len ( ) == cand_sig . inputs_and_output . len ( )
294
+ && iter:: zip ( inputs_and_output, cand_sig . inputs_and_output )
293
295
. all ( |( obl, imp) | self . types_may_unify ( obl, imp) )
294
296
}
295
297
_ => false ,
@@ -308,9 +310,9 @@ impl DeepRejectCtxt {
308
310
TreatParams :: AsCandidateKey => true ,
309
311
} ,
310
312
311
- ty:: Infer ( ty:: IntVar ( _) ) => impl_ty . is_integral ( ) ,
313
+ ty:: Infer ( ty:: IntVar ( _) ) => candidate_ty . is_integral ( ) ,
312
314
313
- ty:: Infer ( ty:: FloatVar ( _) ) => impl_ty . is_floating_point ( ) ,
315
+ ty:: Infer ( ty:: FloatVar ( _) ) => candidate_ty . is_floating_point ( ) ,
314
316
315
317
ty:: Infer ( _) => true ,
316
318
@@ -329,17 +331,22 @@ impl DeepRejectCtxt {
329
331
}
330
332
}
331
333
332
- pub fn consts_may_unify ( self , obligation_ct : ty:: Const < ' _ > , impl_ct : ty:: Const < ' _ > ) -> bool {
333
- let impl_val = match impl_ct. kind ( ) {
334
+ pub fn consts_may_unify (
335
+ self ,
336
+ obligation_ct : ty:: Const < ' _ > ,
337
+ candidate_ct : ty:: Const < ' _ > ,
338
+ ) -> bool {
339
+ let candidate_val = match candidate_ct. kind ( ) {
334
340
ty:: ConstKind :: Expr ( _)
335
341
| ty:: ConstKind :: Param ( _)
336
342
| ty:: ConstKind :: Unevaluated ( _)
343
+ | ty:: ConstKind :: Placeholder ( _)
337
344
| ty:: ConstKind :: Error ( _) => {
338
345
return true ;
339
346
}
340
- ty:: ConstKind :: Value ( impl_val ) => impl_val ,
341
- ty:: ConstKind :: Infer ( _) | ty:: ConstKind :: Bound ( ..) | ty :: ConstKind :: Placeholder ( _ ) => {
342
- bug ! ( "unexpected impl arg: {:?}" , impl_ct )
347
+ ty:: ConstKind :: Value ( candidate_val ) => candidate_val ,
348
+ ty:: ConstKind :: Infer ( _) | ty:: ConstKind :: Bound ( ..) => {
349
+ bug ! ( "unexpected candidate arg: {:?}" , candidate_ct )
343
350
}
344
351
} ;
345
352
@@ -357,7 +364,7 @@ impl DeepRejectCtxt {
357
364
ty:: ConstKind :: Expr ( _) | ty:: ConstKind :: Unevaluated ( _) | ty:: ConstKind :: Error ( _) => {
358
365
true
359
366
}
360
- ty:: ConstKind :: Value ( obl_val) => obl_val == impl_val ,
367
+ ty:: ConstKind :: Value ( obl_val) => obl_val == candidate_val ,
361
368
362
369
ty:: ConstKind :: Infer ( _) => true ,
363
370
0 commit comments