@@ -21,7 +21,7 @@ use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
21
21
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind , ToType } ;
22
22
use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
23
23
use rustc_middle:: traits:: select;
24
- use rustc_middle:: ty:: abstract_const:: AbstractConst ;
24
+ use rustc_middle:: ty:: abstract_const:: { AbstractConst , FailureKind } ;
25
25
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
26
26
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
27
27
use rustc_middle:: ty:: relate:: RelateResult ;
@@ -1683,7 +1683,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1683
1683
#[ instrument( skip( self ) , level = "debug" ) ]
1684
1684
pub fn const_eval_resolve (
1685
1685
& self ,
1686
- param_env : ty:: ParamEnv < ' tcx > ,
1686
+ mut param_env : ty:: ParamEnv < ' tcx > ,
1687
1687
unevaluated : ty:: Unevaluated < ' tcx > ,
1688
1688
span : Option < Span > ,
1689
1689
) -> EvalToValTreeResult < ' tcx > {
@@ -1694,10 +1694,45 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1694
1694
// variables
1695
1695
if substs. has_infer_types_or_consts ( ) {
1696
1696
let ac = AbstractConst :: new ( self . tcx , unevaluated. shrink ( ) ) ;
1697
- if let Ok ( None ) = ac {
1698
- substs = InternalSubsts :: identity_for_item ( self . tcx , unevaluated. def . did ) ;
1699
- } else {
1700
- return Err ( ErrorHandled :: TooGeneric ) ;
1697
+ match ac {
1698
+ Ok ( None ) => {
1699
+ substs = InternalSubsts :: identity_for_item ( self . tcx , unevaluated. def . did ) ;
1700
+ param_env = self . tcx . param_env ( unevaluated. def . did ) ;
1701
+ }
1702
+ Ok ( Some ( ct) ) => {
1703
+ if ct. unify_failure_kind ( self . tcx ) == FailureKind :: Concrete {
1704
+ substs = self . tcx . mk_substs ( substs. iter ( ) . enumerate ( ) . map ( |( idx, arg) | {
1705
+ let needs_replacement =
1706
+ arg. has_param_types_or_consts ( ) || arg. has_infer_types_or_consts ( ) ;
1707
+ match arg. unpack ( ) {
1708
+ GenericArgKind :: Type ( _) if needs_replacement => self
1709
+ . tcx
1710
+ . mk_ty ( ty:: Placeholder ( ty:: PlaceholderType {
1711
+ universe : ty:: UniverseIndex :: ROOT ,
1712
+ name : ty:: BoundVar :: from_usize ( idx) ,
1713
+ } ) )
1714
+ . into ( ) ,
1715
+ GenericArgKind :: Const ( ct) if needs_replacement => self
1716
+ . tcx
1717
+ . mk_const ( ty:: ConstS {
1718
+ ty : ct. ty ( ) ,
1719
+ kind : ty:: ConstKind :: Placeholder ( ty:: PlaceholderConst {
1720
+ universe : ty:: UniverseIndex :: ROOT ,
1721
+ name : ty:: BoundConst {
1722
+ var : ty:: BoundVar :: from_usize ( idx) ,
1723
+ ty : ct. ty ( ) ,
1724
+ } ,
1725
+ } ) ,
1726
+ } )
1727
+ . into ( ) ,
1728
+ _ => arg,
1729
+ }
1730
+ } ) ) ;
1731
+ } else {
1732
+ return Err ( ErrorHandled :: TooGeneric ) ;
1733
+ }
1734
+ }
1735
+ Err ( guar) => return Err ( ErrorHandled :: Reported ( guar) ) ,
1701
1736
}
1702
1737
}
1703
1738
0 commit comments