@@ -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,39 @@ 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) ;
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
+ ) ;
1651
1629
match ac {
1652
1630
Ok ( None ) => {
1653
- substs = InternalSubsts :: identity_for_item ( self . tcx , unevaluated. def . did ) ;
1631
+ substs = InternalSubsts :: identity_for_item ( tcx, unevaluated. def . did ) ;
1654
1632
param_env = self . tcx . param_env ( unevaluated. def . did ) ;
1655
1633
}
1656
1634
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 ( ) {
1660
1636
return Err ( ErrorHandled :: TooGeneric ) ;
1637
+ } else {
1638
+ substs = replace_param_and_infer_substs_with_placeholder ( tcx, substs) ;
1661
1639
}
1662
1640
}
1663
1641
Err ( guar) => return Err ( ErrorHandled :: Reported ( guar) ) ,
1664
1642
}
1665
1643
}
1666
1644
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) ;
1669
1647
debug ! ( ?param_env_erased) ;
1670
1648
debug ! ( ?substs_erased) ;
1671
1649
1672
1650
let unevaluated = ty:: UnevaluatedConst { def : unevaluated. def , substs : substs_erased } ;
1673
1651
1674
1652
// The return value is the evaluated value which doesn't contain any reference to inference
1675
1653
// 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)
1677
1655
}
1678
1656
1679
1657
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:
0 commit comments