Skip to content

Commit 5558a84

Browse files
committed
reviews
1 parent b0b1ad1 commit 5558a84

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

compiler/rustc_trait_selection/src/solve/delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
8484
) -> Option<ty::Const<'tcx>> {
8585
match crate::traits::try_evaluate_const(&self.0, ct, param_env) {
8686
Ok(ct) => Some(ct),
87-
Err(EvaluateConstErr::CTFEFailure(e)) => Some(ty::Const::new_error(self.tcx, e)),
87+
Err(EvaluateConstErr::EvaluationFailure(e)) => Some(ty::Const::new_error(self.tcx, e)),
8888
Err(
8989
EvaluateConstErr::InvalidConstParamTy(_) | EvaluateConstErr::HasGenericsOrInfers,
9090
) => None,

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub fn is_const_evaluatable<'tcx>(
7777
)))
7878
}
7979
Err(
80-
EvaluateConstErr::CTFEFailure(e) | EvaluateConstErr::InvalidConstParamTy(e),
80+
EvaluateConstErr::EvaluationFailure(e)
81+
| EvaluateConstErr::InvalidConstParamTy(e),
8182
) => Err(NotConstEvaluatable::Error(e.into())),
8283
Ok(_) => Ok(()),
8384
}
@@ -137,9 +138,9 @@ pub fn is_const_evaluatable<'tcx>(
137138

138139
Err(err)
139140
}
140-
Err(EvaluateConstErr::CTFEFailure(e) | EvaluateConstErr::InvalidConstParamTy(e)) => {
141-
Err(NotConstEvaluatable::Error(e.into()))
142-
}
141+
Err(
142+
EvaluateConstErr::EvaluationFailure(e) | EvaluateConstErr::InvalidConstParamTy(e),
143+
) => Err(NotConstEvaluatable::Error(e.into())),
143144
Ok(_) => Ok(()),
144145
}
145146
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+26-22
Original file line numberDiff line numberDiff line change
@@ -662,28 +662,32 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
662662

663663
let stalled_on = &mut pending_obligation.stalled_on;
664664

665-
let mut evaluate =
666-
|c: Const<'tcx>| {
667-
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
668-
match super::try_evaluate_const(
669-
self.selcx.infcx,
670-
c,
671-
obligation.param_env,
672-
) {
673-
Ok(val) => Ok(val),
674-
Err(e) => {
675-
if let EvaluateConstErr::HasGenericsOrInfers = e {
676-
stalled_on.extend(unevaluated.args.iter().filter_map(
677-
TyOrConstInferVar::maybe_from_generic_arg,
678-
));
679-
}
680-
Err(e)
681-
}
665+
let mut evaluate = |c: Const<'tcx>| {
666+
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
667+
match super::try_evaluate_const(
668+
self.selcx.infcx,
669+
c,
670+
obligation.param_env,
671+
) {
672+
Ok(val) => Ok(val),
673+
e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
674+
stalled_on.extend(
675+
unevaluated
676+
.args
677+
.iter()
678+
.filter_map(TyOrConstInferVar::maybe_from_generic_arg),
679+
);
680+
e
682681
}
683-
} else {
684-
Ok(c)
682+
e @ Err(
683+
EvaluateConstErr::EvaluationFailure(_)
684+
| EvaluateConstErr::InvalidConstParamTy(_),
685+
) => e,
685686
}
686-
};
687+
} else {
688+
Ok(c)
689+
}
690+
};
687691

688692
match (evaluate(c1), evaluate(c2)) {
689693
(Ok(c1), Ok(c2)) => {
@@ -711,8 +715,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
711715
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
712716
))
713717
}
714-
(Err(EvaluateConstErr::CTFEFailure(e)), _)
715-
| (_, Err(EvaluateConstErr::CTFEFailure(e))) => {
718+
(Err(EvaluateConstErr::EvaluationFailure(e)), _)
719+
| (_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
716720
ProcessResult::Error(FulfillmentErrorCode::Select(
717721
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
718722
))

compiler/rustc_trait_selection/src/traits/mod.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,17 @@ pub fn normalize_param_env_or_error<'tcx>(
485485

486486
#[derive(Debug)]
487487
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.
488491
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.
489495
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),
491499
}
492500

493501
// 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>(
504512
) -> ty::Const<'tcx> {
505513
match try_evaluate_const(infcx, ct, param_env) {
506514
Ok(ct) => ct,
507-
Err(EvaluateConstErr::CTFEFailure(e) | EvaluateConstErr::InvalidConstParamTy(e)) => {
515+
Err(EvaluateConstErr::EvaluationFailure(e) | EvaluateConstErr::InvalidConstParamTy(e)) => {
508516
ty::Const::new_error(infcx.tcx, e)
509517
}
510518
Err(EvaluateConstErr::HasGenericsOrInfers) => ct,
@@ -529,7 +537,7 @@ pub fn try_evaluate_const<'tcx>(
529537

530538
match ct.kind() {
531539
ty::ConstKind::Value(..) => Ok(ct),
532-
ty::ConstKind::Error(e) => Err(EvaluateConstErr::CTFEFailure(e)),
540+
ty::ConstKind::Error(e) => Err(EvaluateConstErr::EvaluationFailure(e)),
533541
ty::ConstKind::Param(_)
534542
| ty::ConstKind::Infer(_)
535543
| ty::ConstKind::Bound(_, _)
@@ -547,7 +555,7 @@ pub fn try_evaluate_const<'tcx>(
547555
Ok(Some(ct)) => {
548556
let ct = tcx.expand_abstract_consts(ct.instantiate(tcx, uv.args));
549557
if let Err(e) = ct.error_reported() {
550-
return Err(EvaluateConstErr::CTFEFailure(e));
558+
return Err(EvaluateConstErr::EvaluationFailure(e));
551559
} else if ct.has_non_region_infer() || ct.has_non_region_param() {
552560
// If the anon const *does* actually use generic parameters or inference variables from
553561
// the generic arguments provided for it, then we should *not* attempt to evaluate it.
@@ -593,7 +601,7 @@ pub fn try_evaluate_const<'tcx>(
593601
Err(EvaluateConstErr::InvalidConstParamTy(e))
594602
}
595603
Err(ErrorHandled::Reported(info, _)) => {
596-
Err(EvaluateConstErr::CTFEFailure(info.into()))
604+
Err(EvaluateConstErr::EvaluationFailure(info.into()))
597605
}
598606
Err(ErrorHandled::TooGeneric(_)) => Err(EvaluateConstErr::HasGenericsOrInfers),
599607
}

compiler/rustc_trait_selection/src/traits/select/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
962962
}
963963
(Err(EvaluateConstErr::InvalidConstParamTy(..)), _)
964964
| (_, Err(EvaluateConstErr::InvalidConstParamTy(..))) => Ok(EvaluatedToErr),
965-
(Err(EvaluateConstErr::CTFEFailure(..)), _)
966-
| (_, Err(EvaluateConstErr::CTFEFailure(..))) => Ok(EvaluatedToErr),
965+
(Err(EvaluateConstErr::EvaluationFailure(..)), _)
966+
| (_, Err(EvaluateConstErr::EvaluationFailure(..))) => Ok(EvaluatedToErr),
967967
(Err(EvaluateConstErr::HasGenericsOrInfers), _)
968968
| (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
969969
if c1.has_non_region_infer() || c2.has_non_region_infer() {

0 commit comments

Comments
 (0)