@@ -493,6 +493,10 @@ pub enum EvaluateConstErr {
493493 /// CTFE failed to evaluate the constant in some unrecoverable way (e.g. encountered a `panic!`).
494494 /// This is also used when the constant was already tainted by error.
495495 EvaluationFailure ( ErrorGuaranteed ) ,
496+ /// The constant requires impossible clauses to hold in order for it to be evaluated. This does not
497+ /// necessarily imply that type checking should error as there may be similar impossible clauses in
498+ /// the type checking environment that can be used to prove this constant wf.
499+ ImpossibleClauses ,
496500}
497501
498502// FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine
@@ -514,7 +518,7 @@ pub fn evaluate_const<'tcx>(
514518 Err ( EvaluateConstErr :: EvaluationFailure ( e) | EvaluateConstErr :: InvalidConstParamTy ( e) ) => {
515519 ty:: Const :: new_error ( infcx. tcx , e)
516520 }
517- Err ( EvaluateConstErr :: HasGenericsOrInfers ) => ct,
521+ Err ( EvaluateConstErr :: ImpossibleClauses | EvaluateConstErr :: HasGenericsOrInfers ) => ct,
518522 }
519523}
520524
@@ -671,7 +675,7 @@ pub fn try_evaluate_const<'tcx>(
671675 // If we are dealing with a fully monomorphic constant then we should ensure that
672676 // it is well formed as otherwise CTFE will ICE. For the same reasons as with
673677 // deferring evaluation of generic/uninferred constants, we do not have to worry
674- // about `generic_const_expr `
678+ // about `generic_const_exprs `
675679 //
676680 // This check is done in an empty environment which is a little weird, however, mir
677681 // bodies with impossible predicates (in an empty environment) are sometimes built as
@@ -681,17 +685,9 @@ pub fn try_evaluate_const<'tcx>(
681685 uv. def ,
682686 tcx. erase_regions ( uv. args ) ,
683687 ) ) {
684- // We treat these consts as rigid instead of an error or delaying a bug as we may
685- // be checking a constant with a trivialy-false where clause that is satisfied from
686- // a trivially-false clause in the environment.
687- //
688- // Delaying a bug would ICE the compiler as we may be in an environment where the
689- // impossible pred actually holds.
690- //
691- // Emitting an error would be wrong as we may be normalizing inside of a probe where
692- // an inference variable was inferred to a concrete value resulting in an impossible
693- // predicate.
694- return Ok ( ct) ;
688+ // We can't delay a bug here as that could ICE the compiler if we are in an environment
689+ // where the impossible pred actually holds due to it also existing in this env.
690+ return Err ( EvaluateConstErr :: ImpossibleClauses ) ;
695691 }
696692
697693 let typing_env = infcx
0 commit comments