@@ -577,6 +577,7 @@ pub fn const_eval_provider<'a, 'tcx>(
577
577
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
578
578
key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
579
579
) -> :: rustc:: mir:: interpret:: ConstEvalResult < ' tcx > {
580
+ // see comment in const_eval_provider for what we're doing here
580
581
if key. param_env . reveal == Reveal :: All {
581
582
let mut key = key. clone ( ) ;
582
583
key. param_env . reveal = Reveal :: UserFacing ;
@@ -596,6 +597,12 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
596
597
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
597
598
key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
598
599
) -> :: rustc:: mir:: interpret:: ConstEvalResult < ' tcx > {
600
+ // so we do a small trick here. We check whether we can evaluate the constant in the more
601
+ // restrictive `Reveal::UserFacing`, which most likely already was computed. In a large
602
+ // percentage of constants that will already have succeeded. Only associated constants of
603
+ // generic functions will fail due to not enough monomorphization information being available
604
+
605
+ // in case we fail in the `UserFacing` variant, we just do the real computation.
599
606
if key. param_env . reveal == Reveal :: All {
600
607
let mut key = key. clone ( ) ;
601
608
key. param_env . reveal = Reveal :: UserFacing ;
0 commit comments