@@ -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,33 @@ 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) ;
1651- match ac {
1652- Ok ( None ) => {
1653- substs = InternalSubsts :: identity_for_item ( self . tcx , unevaluated. def . did ) ;
1654- param_env = self . tcx . param_env ( unevaluated. def . did ) ;
1655- }
1656- 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 {
1660- return Err ( ErrorHandled :: TooGeneric ) ;
1661- }
1624+ if let Some ( ct) = tcx. bound_abstract_const ( unevaluated. def ) ? {
1625+ let ct = tcx. expand_abstract_consts ( ct. subst ( tcx, substs) ) ;
1626+ if let Err ( e) = ct. error_reported ( ) {
1627+ return Err ( ErrorHandled :: Reported ( e) ) ;
1628+ } else if ct. has_non_region_infer ( ) || ct. has_non_region_param ( ) {
1629+ return Err ( ErrorHandled :: TooGeneric ) ;
1630+ } else {
1631+ substs = replace_param_and_infer_substs_with_placeholder ( tcx, substs) ;
16621632 }
1663- Err ( guar) => return Err ( ErrorHandled :: Reported ( guar) ) ,
1633+ } else {
1634+ substs = InternalSubsts :: identity_for_item ( tcx, unevaluated. def . did ) ;
1635+ param_env = tcx. param_env ( unevaluated. def . did ) ;
16641636 }
16651637 }
16661638
1667- let param_env_erased = self . tcx . erase_regions ( param_env) ;
1668- let substs_erased = self . tcx . erase_regions ( substs) ;
1639+ let param_env_erased = tcx. erase_regions ( param_env) ;
1640+ let substs_erased = tcx. erase_regions ( substs) ;
16691641 debug ! ( ?param_env_erased) ;
16701642 debug ! ( ?substs_erased) ;
16711643
16721644 let unevaluated = ty:: UnevaluatedConst { def : unevaluated. def , substs : substs_erased } ;
16731645
16741646 // The return value is the evaluated value which doesn't contain any reference to inference
16751647 // 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)
1648+ tcx. const_eval_resolve_for_typeck ( param_env_erased, unevaluated, span)
16771649 }
16781650
16791651 /// `ty_or_const_infer_var_changed` is equivalent to one of these two:
0 commit comments