@@ -9,6 +9,7 @@ use crate::infer::canonical::Canonical;
9
9
use crate :: middle:: region;
10
10
use crate :: mir:: interpret:: ConstValue ;
11
11
use crate :: mir:: interpret:: Scalar ;
12
+ use crate :: mir:: Promoted ;
12
13
use crate :: ty:: layout:: VariantIdx ;
13
14
use crate :: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , Subst , SubstsRef } ;
14
15
use crate :: ty:: { self , AdtDef , DefIdTree , Discr , Ty , TyCtxt , TypeFlags , TypeFoldable } ;
@@ -2375,7 +2376,7 @@ impl<'tcx> Const<'tcx> {
2375
2376
2376
2377
#[ inline]
2377
2378
pub fn eval ( & self , tcx : TyCtxt < ' tcx > , param_env : ParamEnv < ' tcx > ) -> & Const < ' tcx > {
2378
- let try_const_eval = |did, param_env : ParamEnv < ' tcx > , substs| {
2379
+ let try_const_eval = |did, param_env : ParamEnv < ' tcx > , substs, promoted | {
2379
2380
let param_env_and_substs = param_env. with_reveal_all ( ) . and ( substs) ;
2380
2381
2381
2382
// Avoid querying `tcx.const_eval(...)` with any e.g. inference vars.
@@ -2387,11 +2388,11 @@ impl<'tcx> Const<'tcx> {
2387
2388
2388
2389
// try to resolve e.g. associated constants to their definition on an impl, and then
2389
2390
// evaluate the const.
2390
- tcx. const_eval_resolve ( param_env, did, substs, None ) . ok ( )
2391
+ tcx. const_eval_resolve ( param_env, did, substs, promoted , None ) . ok ( )
2391
2392
} ;
2392
2393
2393
2394
match self . val {
2394
- ConstKind :: Unevaluated ( did, substs) => {
2395
+ ConstKind :: Unevaluated ( did, substs, promoted ) => {
2395
2396
// HACK(eddyb) when substs contain e.g. inference variables,
2396
2397
// attempt using identity substs instead, that will succeed
2397
2398
// when the expression doesn't depend on any parameters.
@@ -2401,12 +2402,12 @@ impl<'tcx> Const<'tcx> {
2401
2402
let identity_substs = InternalSubsts :: identity_for_item ( tcx, did) ;
2402
2403
// The `ParamEnv` needs to match the `identity_substs`.
2403
2404
let identity_param_env = tcx. param_env ( did) ;
2404
- match try_const_eval ( did, identity_param_env, identity_substs) {
2405
+ match try_const_eval ( did, identity_param_env, identity_substs, promoted ) {
2405
2406
Some ( ct) => ct. subst ( tcx, substs) ,
2406
2407
None => self ,
2407
2408
}
2408
2409
} else {
2409
- try_const_eval ( did, param_env, substs) . unwrap_or ( self )
2410
+ try_const_eval ( did, param_env, substs, promoted ) . unwrap_or ( self )
2410
2411
}
2411
2412
}
2412
2413
_ => self ,
@@ -2470,7 +2471,7 @@ pub enum ConstKind<'tcx> {
2470
2471
2471
2472
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
2472
2473
/// variants when the code is monomorphic enough for that.
2473
- Unevaluated ( DefId , SubstsRef < ' tcx > ) ,
2474
+ Unevaluated ( DefId , SubstsRef < ' tcx > , Option < Promoted > ) ,
2474
2475
2475
2476
/// Used to hold computed value.
2476
2477
Value ( ConstValue < ' tcx > ) ,
0 commit comments