@@ -492,9 +492,26 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
492
492
let origin = inner. type_variables ( ) . var_origin ( vid) ;
493
493
let new_var_id =
494
494
inner. type_variables ( ) . new_var ( self . for_universe , origin) ;
495
- let u = Ty :: new_var ( self . tcx ( ) , new_var_id) ;
496
- debug ! ( "replacing original vid={:?} with new={:?}" , vid, u) ;
497
- Ok ( u)
495
+ // If we're in the new solver and create a new inference
496
+ // variable inside of an alias we eagerly constrain that
497
+ // inference variable to prevent unexpected ambiguity errors.
498
+ //
499
+ // This is incomplete as it pulls down the universe of the
500
+ // original inference variable, even though the alias could
501
+ // normalize to a type which does not refer to that type at
502
+ // all. I don't expect this to cause unexpected errors in
503
+ // practice.
504
+ //
505
+ // cc trait-system-refactor-initiative#108
506
+ if self . infcx . next_trait_solver ( )
507
+ && !self . infcx . intercrate
508
+ && self . in_alias
509
+ {
510
+ inner. type_variables ( ) . equate ( vid, new_var_id) ;
511
+ }
512
+
513
+ debug ! ( "replacing original vid={:?} with new={:?}" , vid, new_var_id) ;
514
+ Ok ( Ty :: new_var ( self . tcx ( ) , new_var_id) )
498
515
}
499
516
}
500
517
}
@@ -614,6 +631,15 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
614
631
universe : self . for_universe ,
615
632
} )
616
633
. vid ;
634
+
635
+ // See the comment for type inference variables
636
+ // for more details.
637
+ if self . infcx . next_trait_solver ( )
638
+ && !self . infcx . intercrate
639
+ && self . in_alias
640
+ {
641
+ variable_table. union ( vid, new_var_id)
642
+ }
617
643
Ok ( ty:: Const :: new_var ( self . tcx ( ) , new_var_id, c. ty ( ) ) )
618
644
}
619
645
}
0 commit comments