@@ -613,26 +613,30 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
613613 // of each other. This is currently only used for diagnostics.
614614 // To see why, see the docs in the `type_variables` module.
615615 inner. type_variables ( ) . sub_unify ( vid, new_var_id) ;
616- // If we're in the new solver and create a new inference
617- // variable inside of an alias we eagerly constrain that
618- // inference variable to prevent unexpected ambiguity errors.
619- //
620- // This is incomplete as it pulls down the universe of the
621- // original inference variable, even though the alias could
622- // normalize to a type which does not refer to that type at
623- // all. I don't expect this to cause unexpected errors in
624- // practice.
625- //
626- // We only need to do so for type and const variables, as
627- // region variables do not impact normalization, and will get
628- // correctly constrained by `AliasRelate` later on.
629- //
630- // cc trait-system-refactor-initiative#108
631- if self . infcx . next_trait_solver ( )
632- && !matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence )
633- {
634- match self . state {
635- GeneralizerState :: IncompletelyRelateHigherRankedAlias => {
616+
617+ match self . state {
618+ GeneralizerState :: IncompletelyRelateHigherRankedAlias => {
619+ if self . infcx . next_trait_solver ( )
620+ && !matches ! (
621+ self . infcx. typing_mode( ) ,
622+ TypingMode :: Coherence
623+ )
624+ {
625+ // If we're in the new solver and create a new inference
626+ // variable inside of an alias we eagerly constrain that
627+ // inference variable to prevent unexpected ambiguity errors.
628+ //
629+ // This is incomplete as it pulls down the universe of the
630+ // original inference variable, even though the alias could
631+ // normalize to a type which does not refer to that type at
632+ // all. I don't expect this to cause unexpected errors in
633+ // practice.
634+ //
635+ // We only need to do so for type and const variables, as
636+ // region variables do not impact normalization, and will get
637+ // correctly constrained by `AliasRelate` later on.
638+ //
639+ // cc trait-system-refactor-initiative#108
636640 inner. type_variables ( ) . equate ( vid, new_var_id) ;
637641 }
638642 }
@@ -759,13 +763,16 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
759763 } )
760764 . vid ;
761765
762- // See the comment for type inference variables
763- // for more details.
764- if self . infcx . next_trait_solver ( )
765- && !matches ! ( self . infcx. typing_mode( ) , TypingMode :: Coherence )
766- {
767- match self . state {
768- GeneralizerState :: IncompletelyRelateHigherRankedAlias => {
766+ match self . state {
767+ GeneralizerState :: IncompletelyRelateHigherRankedAlias => {
768+ // See the comment for type inference variables
769+ // for more details.
770+ if self . infcx . next_trait_solver ( )
771+ && !matches ! (
772+ self . infcx. typing_mode( ) ,
773+ TypingMode :: Coherence
774+ )
775+ {
769776 variable_table. union ( vid, new_var_id) ;
770777 }
771778 }
0 commit comments