@@ -23,7 +23,6 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
23
23
use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
24
24
use rustc_middle:: mir:: ConstraintCategory ;
25
25
use rustc_middle:: traits:: select;
26
- use rustc_middle:: ty:: abstract_const:: { AbstractConst , FailureKind } ;
27
26
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
28
27
use rustc_middle:: ty:: fold:: BoundVarReplacerDelegate ;
29
28
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
@@ -713,32 +712,6 @@ impl<'tcx> InferCtxt<'tcx> {
713
712
TypeErrCtxt { infcx : self , typeck_results : None , fallback_has_occurred : false }
714
713
}
715
714
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
-
742
715
pub fn is_in_snapshot ( & self ) -> bool {
743
716
self . in_snapshot . get ( )
744
717
}
@@ -1646,34 +1619,33 @@ impl<'tcx> InferCtxt<'tcx> {
1646
1619
1647
1620
// Postpone the evaluation of constants whose substs depend on inference
1648
1621
// variables
1622
+ let tcx = self . tcx ;
1649
1623
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) ;
1662
1632
}
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 ) ;
1664
1636
}
1665
1637
}
1666
1638
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) ;
1669
1641
debug ! ( ?param_env_erased) ;
1670
1642
debug ! ( ?substs_erased) ;
1671
1643
1672
1644
let unevaluated = ty:: UnevaluatedConst { def : unevaluated. def , substs : substs_erased } ;
1673
1645
1674
1646
// The return value is the evaluated value which doesn't contain any reference to inference
1675
1647
// 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)
1677
1649
}
1678
1650
1679
1651
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:
0 commit comments