@@ -453,16 +453,17 @@ impl<'tcx> InferCtxt<'tcx> {
453453 // Create result arguments: if we found a value for a
454454 // given variable in the loop above, use that. Otherwise, use
455455 // 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 {
459460 // A variable from inside a binder of the query. While ideally these shouldn't
460461 // exist at all, we have to deal with them for now.
461462 self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
462463 universe_map[ u. as_usize ( ) ]
463464 } )
464465 } else if kind. is_existential ( ) {
465- match opt_values[ BoundVar :: new ( index ) ] {
466+ match opt_values[ BoundVar :: new ( var_values . len ( ) ) ] {
466467 Some ( k) => k,
467468 None => self . instantiate_canonical_var ( cause. span , kind, & var_values, |u| {
468469 universe_map[ u. as_usize ( ) ]
@@ -471,20 +472,17 @@ impl<'tcx> InferCtxt<'tcx> {
471472 } else {
472473 // For placeholders which were already part of the input, we simply map this
473474 // universal bound variable back the placeholder of the input.
474- opt_values[ BoundVar :: new ( index ) ]
475+ opt_values[ BoundVar :: new ( var_values . len ( ) ) ]
475476 . 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+ } ) ;
481479
482480 let mut obligations = PredicateObligations :: new ( ) ;
483481
484482 // Carry all newly resolved opaque types to the caller's scope
485483 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) ;
488486 debug ! ( ?a, ?b, "constrain opaque type" ) ;
489487 // We use equate here instead of, for example, just registering the
490488 // opaque type's hidden value directly, because the hidden type may have been an inference
@@ -501,7 +499,7 @@ impl<'tcx> InferCtxt<'tcx> {
501499 ) ;
502500 }
503501
504- Ok ( InferOk { value : result_args , obligations } )
502+ Ok ( InferOk { value : var_values , obligations } )
505503 }
506504
507505 /// Given a "guess" at the values for the canonical variables in
0 commit comments