@@ -23,7 +23,6 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
2323use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
2424use rustc_middle:: mir:: ConstraintCategory ;
2525use rustc_middle:: traits:: select;
26- use rustc_middle:: ty:: abstract_const:: { AbstractConst , FailureKind } ;
2726use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
2827use rustc_middle:: ty:: fold:: BoundVarReplacerDelegate ;
2928use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
@@ -713,32 +712,6 @@ impl<'tcx> InferCtxt<'tcx> {
713712 TypeErrCtxt { infcx : self , typeck_results : None , fallback_has_occurred : false }
714713 }
715714
716- /// calls `tcx.try_unify_abstract_consts` after
717- /// canonicalizing the consts.
718- #[ instrument( skip( self ) , level = "debug" ) ]
719- pub fn try_unify_abstract_consts (
720- & self ,
721- a : ty:: UnevaluatedConst < ' tcx > ,
722- b : ty:: UnevaluatedConst < ' tcx > ,
723- param_env : ty:: ParamEnv < ' tcx > ,
724- ) -> bool {
725- // Reject any attempt to unify two unevaluated constants that contain inference
726- // variables, since inference variables in queries lead to ICEs.
727- if a. substs . has_non_region_infer ( )
728- || b. substs . has_non_region_infer ( )
729- || param_env. has_non_region_infer ( )
730- {
731- debug ! ( "a or b or param_env contain infer vars in its substs -> cannot unify" ) ;
732- return false ;
733- }
734-
735- let param_env_and = param_env. and ( ( a, b) ) ;
736- let erased = self . tcx . erase_regions ( param_env_and) ;
737- debug ! ( "after erase_regions: {:?}" , erased) ;
738-
739- self . tcx . try_unify_abstract_consts ( erased)
740- }
741-
742715 pub fn is_in_snapshot ( & self ) -> bool {
743716 self . in_snapshot . get ( )
744717 }
@@ -1646,34 +1619,39 @@ impl<'tcx> InferCtxt<'tcx> {
16461619
16471620 // Postpone the evaluation of constants whose substs depend on inference
16481621 // variables
1622+ let tcx = self . tcx ;
16491623 if substs. has_non_region_infer ( ) {
1650- let ac = AbstractConst :: new ( self . tcx , unevaluated) ;
1624+ let substs_erased = tcx. erase_regions ( unevaluated. substs ) ;
1625+ let ac = tcx. expand_bound_abstract_const (
1626+ tcx. bound_abstract_const ( unevaluated. def ) ,
1627+ substs_erased,
1628+ ) ;
16511629 match ac {
16521630 Ok ( None ) => {
1653- substs = InternalSubsts :: identity_for_item ( self . tcx , unevaluated. def . did ) ;
1631+ substs = InternalSubsts :: identity_for_item ( tcx, unevaluated. def . did ) ;
16541632 param_env = self . tcx . param_env ( unevaluated. def . did ) ;
16551633 }
16561634 Ok ( Some ( ct) ) => {
1657- if ct. unify_failure_kind ( self . tcx ) == FailureKind :: Concrete {
1658- substs = replace_param_and_infer_substs_with_placeholder ( self . tcx , substs) ;
1659- } else {
1635+ if ct. has_non_region_infer ( ) || ct. has_non_region_param ( ) {
16601636 return Err ( ErrorHandled :: TooGeneric ) ;
1637+ } else {
1638+ substs = replace_param_and_infer_substs_with_placeholder ( tcx, substs) ;
16611639 }
16621640 }
16631641 Err ( guar) => return Err ( ErrorHandled :: Reported ( guar) ) ,
16641642 }
16651643 }
16661644
1667- let param_env_erased = self . tcx . erase_regions ( param_env) ;
1668- let substs_erased = self . tcx . erase_regions ( substs) ;
1645+ let param_env_erased = tcx. erase_regions ( param_env) ;
1646+ let substs_erased = tcx. erase_regions ( substs) ;
16691647 debug ! ( ?param_env_erased) ;
16701648 debug ! ( ?substs_erased) ;
16711649
16721650 let unevaluated = ty:: UnevaluatedConst { def : unevaluated. def , substs : substs_erased } ;
16731651
16741652 // The return value is the evaluated value which doesn't contain any reference to inference
16751653 // variables, thus we don't need to substitute back the original values.
1676- self . tcx . const_eval_resolve_for_typeck ( param_env_erased, unevaluated, span)
1654+ tcx. const_eval_resolve_for_typeck ( param_env_erased, unevaluated, span)
16771655 }
16781656
16791657 /// `ty_or_const_infer_var_changed` is equivalent to one of these two:
0 commit comments