@@ -262,50 +262,20 @@ impl<'tcx> InferCtxt<'tcx> {
262
262
263
263
let constraint_category = cause. to_constraint_category ( ) ;
264
264
265
- for ( index, original_value) in original_values. var_values . iter ( ) . enumerate ( ) {
265
+ for ( index, & original_value) in original_values. var_values . iter ( ) . enumerate ( ) {
266
266
// ...with the value `v_r` of that variable from the query.
267
267
let result_value = query_response. instantiate_projected ( self . tcx , & result_args, |v| {
268
268
v. var_values [ BoundVar :: new ( index) ]
269
269
} ) ;
270
- match ( original_value. unpack ( ) , result_value. unpack ( ) ) {
271
- ( GenericArgKind :: Lifetime ( re1) , GenericArgKind :: Lifetime ( re2) )
272
- if re1. is_erased ( ) && re2. is_erased ( ) =>
273
- {
274
- // No action needed.
275
- }
276
-
277
- ( GenericArgKind :: Lifetime ( v_o) , GenericArgKind :: Lifetime ( v_r) ) => {
278
- // To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
279
- if v_o != v_r {
280
- output_query_region_constraints
281
- . outlives
282
- . push ( ( ty:: OutlivesPredicate ( v_o. into ( ) , v_r) , constraint_category) ) ;
283
- output_query_region_constraints
284
- . outlives
285
- . push ( ( ty:: OutlivesPredicate ( v_r. into ( ) , v_o) , constraint_category) ) ;
286
- }
287
- }
288
-
289
- ( GenericArgKind :: Type ( v1) , GenericArgKind :: Type ( v2) ) => {
290
- obligations. extend (
291
- self . at ( & cause, param_env)
292
- . eq ( DefineOpaqueTypes :: Yes , v1, v2) ?
293
- . into_obligations ( ) ,
294
- ) ;
295
- }
296
-
297
- ( GenericArgKind :: Const ( v1) , GenericArgKind :: Const ( v2) ) => {
298
- obligations. extend (
299
- self . at ( & cause, param_env)
300
- . eq ( DefineOpaqueTypes :: Yes , v1, v2) ?
301
- . into_obligations ( ) ,
302
- ) ;
303
- }
304
-
305
- _ => {
306
- bug ! ( "kind mismatch, cannot unify {:?} and {:?}" , original_value, result_value) ;
307
- }
308
- }
270
+ self . equate_generic_arg (
271
+ original_value,
272
+ result_value,
273
+ output_query_region_constraints,
274
+ constraint_category,
275
+ & mut obligations,
276
+ cause,
277
+ param_env,
278
+ ) ?;
309
279
}
310
280
311
281
// ...also include the other query region constraints from the query.
@@ -335,6 +305,57 @@ impl<'tcx> InferCtxt<'tcx> {
335
305
Ok ( InferOk { value : user_result, obligations } )
336
306
}
337
307
308
+ fn equate_generic_arg (
309
+ & self ,
310
+ original_value : GenericArg < ' tcx > ,
311
+ result_value : GenericArg < ' tcx > ,
312
+ output_query_region_constraints : & mut QueryRegionConstraints < ' tcx > ,
313
+ constraint_category : ConstraintCategory < ' tcx > ,
314
+ obligations : & mut Vec < Obligation < ' tcx , ty:: Predicate < ' tcx > > > ,
315
+ cause : & ObligationCause < ' tcx > ,
316
+ param_env : ty:: ParamEnv < ' tcx > ,
317
+ ) -> Result < ( ) , ty:: error:: TypeError < ' tcx > > {
318
+ Ok ( match ( original_value. unpack ( ) , result_value. unpack ( ) ) {
319
+ ( GenericArgKind :: Lifetime ( re1) , GenericArgKind :: Lifetime ( re2) )
320
+ if re1. is_erased ( ) && re2. is_erased ( ) =>
321
+ {
322
+ // No action needed.
323
+ }
324
+
325
+ ( GenericArgKind :: Lifetime ( v_o) , GenericArgKind :: Lifetime ( v_r) ) => {
326
+ // To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
327
+ if v_o != v_r {
328
+ output_query_region_constraints
329
+ . outlives
330
+ . push ( ( ty:: OutlivesPredicate ( v_o. into ( ) , v_r) , constraint_category) ) ;
331
+ output_query_region_constraints
332
+ . outlives
333
+ . push ( ( ty:: OutlivesPredicate ( v_r. into ( ) , v_o) , constraint_category) ) ;
334
+ }
335
+ }
336
+
337
+ ( GenericArgKind :: Type ( v1) , GenericArgKind :: Type ( v2) ) => {
338
+ obligations. extend (
339
+ self . at ( & cause, param_env)
340
+ . eq ( DefineOpaqueTypes :: Yes , v1, v2) ?
341
+ . into_obligations ( ) ,
342
+ ) ;
343
+ }
344
+
345
+ ( GenericArgKind :: Const ( v1) , GenericArgKind :: Const ( v2) ) => {
346
+ obligations. extend (
347
+ self . at ( & cause, param_env)
348
+ . eq ( DefineOpaqueTypes :: Yes , v1, v2) ?
349
+ . into_obligations ( ) ,
350
+ ) ;
351
+ }
352
+
353
+ _ => {
354
+ bug ! ( "kind mismatch, cannot unify {:?} and {:?}" , original_value, result_value) ;
355
+ }
356
+ } )
357
+ }
358
+
338
359
/// Given the original values and the (canonicalized) result from
339
360
/// computing a query, returns an instantiation that can be applied
340
361
/// to the query result to convert the result back into the
0 commit comments