@@ -485,9 +485,17 @@ pub fn normalize_param_env_or_error<'tcx>(
485
485
486
486
#[ derive( Debug ) ]
487
487
pub enum EvaluateConstErr {
488
+ /// The constant being evaluated was either a generic parameter or inference variable, *or*,
489
+ /// some unevaluated constant with either generic parameters or inference variables in its
490
+ /// generic arguments.
488
491
HasGenericsOrInfers ,
492
+ /// The type this constant evalauted to is not valid for use in const generics. This should
493
+ /// always result in an error when checking the constant is correctly typed for the parameter
494
+ /// it is an argument to, so a bug is delayed when encountering this.
489
495
InvalidConstParamTy ( ErrorGuaranteed ) ,
490
- CTFEFailure ( ErrorGuaranteed ) ,
496
+ /// CTFE failed to evaluate the constant in some unrecoverable way (e.g. encountered a `panic!`).
497
+ /// This is also used when the constant was already tainted by error.
498
+ EvaluationFailure ( ErrorGuaranteed ) ,
491
499
}
492
500
493
501
// FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine
@@ -504,7 +512,7 @@ pub fn evaluate_const<'tcx>(
504
512
) -> ty:: Const < ' tcx > {
505
513
match try_evaluate_const ( infcx, ct, param_env) {
506
514
Ok ( ct) => ct,
507
- Err ( EvaluateConstErr :: CTFEFailure ( e) | EvaluateConstErr :: InvalidConstParamTy ( e) ) => {
515
+ Err ( EvaluateConstErr :: EvaluationFailure ( e) | EvaluateConstErr :: InvalidConstParamTy ( e) ) => {
508
516
ty:: Const :: new_error ( infcx. tcx , e)
509
517
}
510
518
Err ( EvaluateConstErr :: HasGenericsOrInfers ) => ct,
@@ -529,7 +537,7 @@ pub fn try_evaluate_const<'tcx>(
529
537
530
538
match ct. kind ( ) {
531
539
ty:: ConstKind :: Value ( ..) => Ok ( ct) ,
532
- ty:: ConstKind :: Error ( e) => Err ( EvaluateConstErr :: CTFEFailure ( e) ) ,
540
+ ty:: ConstKind :: Error ( e) => Err ( EvaluateConstErr :: EvaluationFailure ( e) ) ,
533
541
ty:: ConstKind :: Param ( _)
534
542
| ty:: ConstKind :: Infer ( _)
535
543
| ty:: ConstKind :: Bound ( _, _)
@@ -547,7 +555,7 @@ pub fn try_evaluate_const<'tcx>(
547
555
Ok ( Some ( ct) ) => {
548
556
let ct = tcx. expand_abstract_consts ( ct. instantiate ( tcx, uv. args ) ) ;
549
557
if let Err ( e) = ct. error_reported ( ) {
550
- return Err ( EvaluateConstErr :: CTFEFailure ( e) ) ;
558
+ return Err ( EvaluateConstErr :: EvaluationFailure ( e) ) ;
551
559
} else if ct. has_non_region_infer ( ) || ct. has_non_region_param ( ) {
552
560
// If the anon const *does* actually use generic parameters or inference variables from
553
561
// the generic arguments provided for it, then we should *not* attempt to evaluate it.
@@ -593,7 +601,7 @@ pub fn try_evaluate_const<'tcx>(
593
601
Err ( EvaluateConstErr :: InvalidConstParamTy ( e) )
594
602
}
595
603
Err ( ErrorHandled :: Reported ( info, _) ) => {
596
- Err ( EvaluateConstErr :: CTFEFailure ( info. into ( ) ) )
604
+ Err ( EvaluateConstErr :: EvaluationFailure ( info. into ( ) ) )
597
605
}
598
606
Err ( ErrorHandled :: TooGeneric ( _) ) => Err ( EvaluateConstErr :: HasGenericsOrInfers ) ,
599
607
}
0 commit comments