@@ -459,16 +459,17 @@ impl<'tcx> InferCtxt<'tcx> {
459459 // Create result arguments: if we found a value for a
460460 // given variable in the loop above, use that. Otherwise, use
461461 // a fresh inference variable.
462- let mut var_values = Vec :: with_capacity ( query_response. variables . len ( ) ) ;
463- for ( index, kind) in query_response. variables . iter ( ) . enumerate ( ) {
464- let value = if kind. universe ( ) != ty:: UniverseIndex :: ROOT {
462+ let tcx = self . tcx ;
463+ let variables = query_response. variables ;
464+ let var_values = CanonicalVarValues :: instantiate ( tcx, variables, |var_values, kind| {
465+ if kind. universe ( ) != ty:: UniverseIndex :: ROOT {
465466 // A variable from inside a binder of the query. While ideally these shouldn't
466467 // exist at all, we have to deal with them for now.
467468 self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
468469 universe_map[ u. as_usize ( ) ]
469470 } )
470471 } else if kind. is_existential ( ) {
471- match opt_values[ BoundVar :: new ( index ) ] {
472+ match opt_values[ BoundVar :: new ( var_values . len ( ) ) ] {
472473 Some ( k) => k,
473474 None => self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
474475 universe_map[ u. as_usize ( ) ]
@@ -477,20 +478,17 @@ impl<'tcx> InferCtxt<'tcx> {
477478 } else {
478479 // For placeholders which were already part of the input, we simply map this
479480 // universal bound variable back the placeholder of the input.
480- opt_values[ BoundVar :: new ( index ) ]
481+ opt_values[ BoundVar :: new ( var_values . len ( ) ) ]
481482 . expect ( "expected placeholder to be unified with itself during response" )
482- } ;
483- var_values. push ( value) ;
484- }
485-
486- let result_args = CanonicalVarValues { var_values : self . tcx . mk_args ( & var_values) } ;
483+ }
484+ } ) ;
487485
488486 let mut obligations = PredicateObligations :: new ( ) ;
489487
490488 // Carry all newly resolved opaque types to the caller's scope
491489 for & ( a, b) in & query_response. value . opaque_types {
492- let a = instantiate_value ( self . tcx , & result_args , a) ;
493- let b = instantiate_value ( self . tcx , & result_args , b) ;
490+ let a = instantiate_value ( self . tcx , & var_values , a) ;
491+ let b = instantiate_value ( self . tcx , & var_values , b) ;
494492 debug ! ( ?a, ?b, "constrain opaque type" ) ;
495493 // We use equate here instead of, for example, just registering the
496494 // opaque type's hidden value directly, because the hidden type may have been an inference
@@ -507,7 +505,7 @@ impl<'tcx> InferCtxt<'tcx> {
507505 ) ;
508506 }
509507
510- Ok ( InferOk { value : result_args , obligations } )
508+ Ok ( InferOk { value : var_values , obligations } )
511509 }
512510
513511 /// Given a "guess" at the values for the canonical variables in
0 commit comments