@@ -9,6 +9,7 @@ use crate::infer::canonical::Canonical;
99use crate :: middle:: region;
1010use crate :: mir:: interpret:: ConstValue ;
1111use crate :: mir:: interpret:: Scalar ;
12+ use crate :: mir:: Promoted ;
1213use crate :: ty:: layout:: VariantIdx ;
1314use crate :: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , Subst , SubstsRef } ;
1415use crate :: ty:: { self , AdtDef , DefIdTree , Discr , Ty , TyCtxt , TypeFlags , TypeFoldable } ;
@@ -2375,7 +2376,7 @@ impl<'tcx> Const<'tcx> {
23752376
23762377 #[ inline]
23772378 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 | {
23792380 let param_env_and_substs = param_env. with_reveal_all ( ) . and ( substs) ;
23802381
23812382 // Avoid querying `tcx.const_eval(...)` with any e.g. inference vars.
@@ -2387,11 +2388,11 @@ impl<'tcx> Const<'tcx> {
23872388
23882389 // try to resolve e.g. associated constants to their definition on an impl, and then
23892390 // 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 ( )
23912392 } ;
23922393
23932394 match self . val {
2394- ConstKind :: Unevaluated ( did, substs) => {
2395+ ConstKind :: Unevaluated ( did, substs, promoted ) => {
23952396 // HACK(eddyb) when substs contain e.g. inference variables,
23962397 // attempt using identity substs instead, that will succeed
23972398 // when the expression doesn't depend on any parameters.
@@ -2401,12 +2402,12 @@ impl<'tcx> Const<'tcx> {
24012402 let identity_substs = InternalSubsts :: identity_for_item ( tcx, did) ;
24022403 // The `ParamEnv` needs to match the `identity_substs`.
24032404 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 ) {
24052406 Some ( ct) => ct. subst ( tcx, substs) ,
24062407 None => self ,
24072408 }
24082409 } else {
2409- try_const_eval ( did, param_env, substs) . unwrap_or ( self )
2410+ try_const_eval ( did, param_env, substs, promoted ) . unwrap_or ( self )
24102411 }
24112412 }
24122413 _ => self ,
@@ -2470,7 +2471,7 @@ pub enum ConstKind<'tcx> {
24702471
24712472 /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
24722473 /// variants when the code is monomorphic enough for that.
2473- Unevaluated ( DefId , SubstsRef < ' tcx > ) ,
2474+ Unevaluated ( DefId , SubstsRef < ' tcx > , Option < Promoted > ) ,
24742475
24752476 /// Used to hold computed value.
24762477 Value ( ConstValue < ' tcx > ) ,
0 commit comments