@@ -21,7 +21,7 @@ use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
2121use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind , ToType } ;
2222use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
2323use rustc_middle:: traits:: select;
24- use rustc_middle:: ty:: abstract_const:: AbstractConst ;
24+ use rustc_middle:: ty:: abstract_const:: { AbstractConst , FailureKind } ;
2525use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
2626use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
2727use rustc_middle:: ty:: relate:: RelateResult ;
@@ -1683,7 +1683,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16831683 #[ instrument( skip( self ) , level = "debug" ) ]
16841684 pub fn const_eval_resolve (
16851685 & self ,
1686- param_env : ty:: ParamEnv < ' tcx > ,
1686+ mut param_env : ty:: ParamEnv < ' tcx > ,
16871687 unevaluated : ty:: Unevaluated < ' tcx > ,
16881688 span : Option < Span > ,
16891689 ) -> EvalToValTreeResult < ' tcx > {
@@ -1694,10 +1694,45 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16941694 // variables
16951695 if substs. has_infer_types_or_consts ( ) {
16961696 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) ) ,
17011736 }
17021737 }
17031738
0 commit comments