@@ -13,7 +13,9 @@ use std::iter;
13
13
use rustc_index:: { Idx , IndexVec } ;
14
14
use rustc_middle:: arena:: ArenaAllocatable ;
15
15
use rustc_middle:: mir:: ConstraintCategory ;
16
- use rustc_middle:: ty:: { self , BoundVar , GenericArg , GenericArgKind , Ty , TyCtxt , TypeFoldable } ;
16
+ use rustc_middle:: ty:: {
17
+ self , BoundVar , CanonicalVarKind , GenericArg , GenericArgKind , Ty , TyCtxt , TypeFoldable ,
18
+ } ;
17
19
use rustc_middle:: { bug, span_bug} ;
18
20
use tracing:: { debug, instrument} ;
19
21
@@ -408,16 +410,7 @@ impl<'tcx> InferCtxt<'tcx> {
408
410
for ( original_value, result_value) in iter:: zip ( & original_values. var_values , result_values)
409
411
{
410
412
match result_value. unpack ( ) {
411
- GenericArgKind :: Type ( result_value) => {
412
- // e.g., here `result_value` might be `?0` in the example above...
413
- if let ty:: Bound ( debruijn, b) = * result_value. kind ( ) {
414
- // ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
415
-
416
- // We only allow a `ty::INNERMOST` index in generic parameters.
417
- assert_eq ! ( debruijn, ty:: INNERMOST ) ;
418
- opt_values[ b. var ] = Some ( * original_value) ;
419
- }
420
- }
413
+ GenericArgKind :: Type ( _) => { }
421
414
GenericArgKind :: Lifetime ( result_value) => {
422
415
// e.g., here `result_value` might be `'?1` in the example above...
423
416
if let ty:: ReBound ( debruijn, br) = result_value. kind ( ) {
@@ -443,32 +436,34 @@ impl<'tcx> InferCtxt<'tcx> {
443
436
// Create result arguments: if we found a value for a
444
437
// given variable in the loop above, use that. Otherwise, use
445
438
// a fresh inference variable.
446
- let result_args = CanonicalVarValues {
447
- var_values : self . tcx . mk_args_from_iter (
448
- query_response. variables . iter ( ) . enumerate ( ) . map ( |( index, info) | {
449
- if info. universe ( ) != ty:: UniverseIndex :: ROOT {
450
- // A variable from inside a binder of the query. While ideally these shouldn't
451
- // exist at all, we have to deal with them for now.
452
- self . instantiate_canonical_var ( cause. span , info, |u| {
453
- universe_map[ u. as_usize ( ) ]
454
- } )
455
- } else if info. is_existential ( ) {
456
- match opt_values[ BoundVar :: new ( index) ] {
457
- Some ( k) => k,
458
- None => self . instantiate_canonical_var ( cause. span , info, |u| {
459
- universe_map[ u. as_usize ( ) ]
460
- } ) ,
461
- }
462
- } else {
463
- // For placeholders which were already part of the input, we simply map this
464
- // universal bound variable back the placeholder of the input.
465
- opt_values[ BoundVar :: new ( index) ] . expect (
466
- "expected placeholder to be unified with itself during response" ,
467
- )
468
- }
469
- } ) ,
470
- ) ,
471
- } ;
439
+ let mut var_values = Vec :: with_capacity ( query_response. variables . len ( ) ) ;
440
+ for ( index, info) in query_response. variables . iter ( ) . enumerate ( ) {
441
+ let value = if info. universe ( ) != ty:: UniverseIndex :: ROOT {
442
+ // A variable from inside a binder of the query. While ideally these shouldn't
443
+ // exist at all, we have to deal with them for now.
444
+ self . instantiate_canonical_var ( cause. span , info, & var_values, |u| {
445
+ universe_map[ u. as_usize ( ) ]
446
+ } )
447
+ } else if info. is_existential ( ) {
448
+ // As an optimization we sometimes avoid creating a new inference variable here.
449
+ // We need to still make sure to register any subtype relations returned by the
450
+ // query.
451
+ match opt_values[ BoundVar :: new ( index) ] {
452
+ Some ( v) => v,
453
+ None => self . instantiate_canonical_var ( cause. span , info, & var_values, |u| {
454
+ universe_map[ u. as_usize ( ) ]
455
+ } ) ,
456
+ }
457
+ } else {
458
+ // For placeholders which were already part of the input, we simply map this
459
+ // universal bound variable back the placeholder of the input.
460
+ opt_values[ BoundVar :: new ( index) ]
461
+ . expect ( "expected placeholder to be unified with itself during response" )
462
+ } ;
463
+ var_values. push ( value)
464
+ }
465
+
466
+ let result_args = CanonicalVarValues { var_values : self . tcx . mk_args ( & var_values) } ;
472
467
473
468
let mut obligations = PredicateObligations :: new ( ) ;
474
469
0 commit comments