@@ -453,16 +453,17 @@ impl<'tcx> InferCtxt<'tcx> {
453
453
// Create result arguments: if we found a value for a
454
454
// given variable in the loop above, use that. Otherwise, use
455
455
// a fresh inference variable.
456
- let mut var_values = Vec :: with_capacity ( query_response. variables . len ( ) ) ;
457
- for ( index, kind) in query_response. variables . iter ( ) . enumerate ( ) {
458
- let value = if kind. universe ( ) != ty:: UniverseIndex :: ROOT {
456
+ let tcx = self . tcx ;
457
+ let variables = query_response. variables ;
458
+ let var_values = CanonicalVarValues :: instantiate ( tcx, variables, |var_values, kind| {
459
+ if kind. universe ( ) != ty:: UniverseIndex :: ROOT {
459
460
// A variable from inside a binder of the query. While ideally these shouldn't
460
461
// exist at all, we have to deal with them for now.
461
462
self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
462
463
universe_map[ u. as_usize ( ) ]
463
464
} )
464
465
} else if kind. is_existential ( ) {
465
- match opt_values[ BoundVar :: new ( index ) ] {
466
+ match opt_values[ BoundVar :: new ( var_values . len ( ) ) ] {
466
467
Some ( k) => k,
467
468
None => self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
468
469
universe_map[ u. as_usize ( ) ]
@@ -471,20 +472,17 @@ impl<'tcx> InferCtxt<'tcx> {
471
472
} else {
472
473
// For placeholders which were already part of the input, we simply map this
473
474
// universal bound variable back the placeholder of the input.
474
- opt_values[ BoundVar :: new ( index ) ]
475
+ opt_values[ BoundVar :: new ( var_values . len ( ) ) ]
475
476
. expect ( "expected placeholder to be unified with itself during response" )
476
- } ;
477
- var_values. push ( value) ;
478
- }
479
-
480
- let result_args = CanonicalVarValues { var_values : self . tcx . mk_args ( & var_values) } ;
477
+ }
478
+ } ) ;
481
479
482
480
let mut obligations = PredicateObligations :: new ( ) ;
483
481
484
482
// Carry all newly resolved opaque types to the caller's scope
485
483
for & ( a, b) in & query_response. value . opaque_types {
486
- let a = instantiate_value ( self . tcx , & result_args , a) ;
487
- let b = instantiate_value ( self . tcx , & result_args , b) ;
484
+ let a = instantiate_value ( self . tcx , & var_values , a) ;
485
+ let b = instantiate_value ( self . tcx , & var_values , b) ;
488
486
debug ! ( ?a, ?b, "constrain opaque type" ) ;
489
487
// We use equate here instead of, for example, just registering the
490
488
// opaque type's hidden value directly, because the hidden type may have been an inference
@@ -501,7 +499,7 @@ impl<'tcx> InferCtxt<'tcx> {
501
499
) ;
502
500
}
503
501
504
- Ok ( InferOk { value : result_args , obligations } )
502
+ Ok ( InferOk { value : var_values , obligations } )
505
503
}
506
504
507
505
/// Given a "guess" at the values for the canonical variables in
0 commit comments