rename some variants in FulfillmentErrorCode

This commit is contained in:
Michael Goulet 2024-05-09 14:09:55 -04:00
parent cf774742b6
commit 04c049498d
9 changed files with 46 additions and 62 deletions

View File

@ -1344,7 +1344,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MaybeIncorrect,
);
for error in errors {
if let FulfillmentErrorCode::SelectionError(
if let FulfillmentErrorCode::Select(
SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

View File

@ -1283,7 +1283,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
// The type doesn't implement Clone because of unmet obligations.
for error in errors {
if let traits::FulfillmentErrorCode::SelectionError(
if let traits::FulfillmentErrorCode::Select(
traits::SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

View File

@ -360,12 +360,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: &traits::FulfillmentError<'tcx>,
span: Span,
) -> bool {
if let traits::FulfillmentErrorCode::SelectionError(
traits::SelectionError::SignatureMismatch(box traits::SignatureMismatchData {
expected_trait_ref,
..
}),
) = error.code
if let traits::FulfillmentErrorCode::Select(traits::SelectionError::SignatureMismatch(
box traits::SignatureMismatchData { expected_trait_ref, .. },
)) = error.code
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
expected_trait_ref.self_ty().kind()
&& span.overlaps(self.tcx.def_span(*def_id))

View File

@ -1700,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
for error in errors {
if let traits::FulfillmentErrorCode::SelectionError(
if let traits::FulfillmentErrorCode::Select(
traits::SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =

View File

@ -138,10 +138,10 @@ pub enum FulfillmentErrorCode<'tcx> {
/// Inherently impossible to fulfill; this trait is implemented if and only
/// if it is already implemented.
Cycle(Vec<PredicateObligation<'tcx>>),
SelectionError(SelectionError<'tcx>),
ProjectionError(MismatchedProjectionTypes<'tcx>),
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
Select(SelectionError<'tcx>),
Project(MismatchedProjectionTypes<'tcx>),
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquate(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
Ambiguity {
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
@ -209,10 +209,10 @@ impl<'tcx> FulfillmentError<'tcx> {
pub fn is_true_error(&self) -> bool {
match self.code {
FulfillmentErrorCode::SelectionError(_)
| FulfillmentErrorCode::ProjectionError(_)
| FulfillmentErrorCode::SubtypeError(_, _)
| FulfillmentErrorCode::ConstEquateError(_, _) => true,
FulfillmentErrorCode::Select(_)
| FulfillmentErrorCode::Project(_)
| FulfillmentErrorCode::Subtype(_, _)
| FulfillmentErrorCode::ConstEquate(_, _) => true,
FulfillmentErrorCode::Cycle(_) | FulfillmentErrorCode::Ambiguity { overflow: _ } => {
false
}

View File

@ -39,12 +39,12 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use traits::FulfillmentErrorCode::*;
match *self {
SelectionError(ref e) => write!(f, "{e:?}"),
ProjectionError(ref e) => write!(f, "{e:?}"),
SubtypeError(ref a, ref b) => {
Select(ref e) => write!(f, "{e:?}"),
Project(ref e) => write!(f, "{e:?}"),
Subtype(ref a, ref b) => {
write!(f, "CodeSubtypeError({a:?}, {b:?})")
}
ConstEquateError(ref a, ref b) => {
ConstEquate(ref a, ref b) => {
write!(f, "CodeConstEquateError({a:?}, {b:?})")
}
Ambiguity { overflow: None } => write!(f, "Ambiguity"),

View File

@ -203,39 +203,35 @@ fn fulfillment_error_for_no_solution<'tcx>(
let code = match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
FulfillmentErrorCode::ProjectionError(
FulfillmentErrorCode::Project(
// FIXME: This could be a `Sorts` if the term is a type
MismatchedProjectionTypes { err: TypeError::Mismatch },
)
}
ty::PredicateKind::NormalizesTo(..) => {
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes {
err: TypeError::Mismatch,
})
FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
}
ty::PredicateKind::AliasRelate(_, _, _) => {
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes {
err: TypeError::Mismatch,
})
FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
}
ty::PredicateKind::Subtype(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe(
obligation.predicate.kind().rebind((pred.a, pred.b)),
);
let expected_found = ExpectedFound::new(true, a, b);
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
FulfillmentErrorCode::Subtype(expected_found, TypeError::Sorts(expected_found))
}
ty::PredicateKind::Coerce(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe(
obligation.predicate.kind().rebind((pred.a, pred.b)),
);
let expected_found = ExpectedFound::new(false, a, b);
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
FulfillmentErrorCode::Subtype(expected_found, TypeError::Sorts(expected_found))
}
ty::PredicateKind::Clause(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::Ambiguous => {
FulfillmentErrorCode::SelectionError(SelectionError::Unimplemented)
FulfillmentErrorCode::Select(SelectionError::Unimplemented)
}
ty::PredicateKind::ConstEquate(..) => {
bug!("unexpected goal: {obligation:?}")

View File

@ -1504,13 +1504,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
match error.code {
FulfillmentErrorCode::SelectionError(ref selection_error) => self
.report_selection_error(
error.obligation.clone(),
&error.root_obligation,
selection_error,
),
FulfillmentErrorCode::ProjectionError(ref e) => {
FulfillmentErrorCode::Select(ref selection_error) => self.report_selection_error(
error.obligation.clone(),
&error.root_obligation,
selection_error,
),
FulfillmentErrorCode::Project(ref e) => {
self.report_projection_error(&error.obligation, e)
}
FulfillmentErrorCode::Ambiguity { overflow: None } => {
@ -1519,7 +1518,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => {
self.report_overflow_no_abort(error.obligation.clone(), suggest_increasing_limit)
}
FulfillmentErrorCode::SubtypeError(ref expected_found, ref err) => self
FulfillmentErrorCode::Subtype(ref expected_found, ref err) => self
.report_mismatched_types(
&error.obligation.cause,
expected_found.expected,
@ -1527,7 +1526,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
*err,
)
.emit(),
FulfillmentErrorCode::ConstEquateError(ref expected_found, ref err) => {
FulfillmentErrorCode::ConstEquate(ref expected_found, ref err) => {
let mut diag = self.report_mismatched_consts(
&error.obligation.cause,
expected_found.expected,

View File

@ -411,7 +411,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
ProcessResult::Error(FulfillmentErrorCode::SelectionError(Unimplemented))
ProcessResult::Error(FulfillmentErrorCode::Select(Unimplemented))
} else {
ProcessResult::Changed(vec![])
}
@ -435,7 +435,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ty,
) {
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
SelectionError::Unimplemented,
)),
}
@ -493,10 +493,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
Ok(Err(err)) => {
let expected_found =
ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
expected_found,
err,
))
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
}
}
}
@ -516,10 +513,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
Ok(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
Ok(Err(err)) => {
let expected_found = ExpectedFound::new(false, coerce.a, coerce.b);
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
expected_found,
err,
))
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
}
}
}
@ -542,7 +536,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
Err(
e @ NotConstEvaluatable::MentionsParam
| e @ NotConstEvaluatable::Error(_),
) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
) => ProcessResult::Error(FulfillmentErrorCode::Select(
SelectionError::NotConstEvaluatable(e),
)),
}
@ -638,7 +632,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
}
Err(err) => {
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
ExpectedFound::new(true, c1, c2),
err,
))
@ -646,13 +640,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}
}
(Err(ErrorHandled::Reported(reported, _)), _)
| (_, Err(ErrorHandled::Reported(reported, _))) => {
ProcessResult::Error(FulfillmentErrorCode::SelectionError(
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(
reported.into(),
)),
))
}
| (_, Err(ErrorHandled::Reported(reported, _))) => ProcessResult::Error(
FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(
NotConstEvaluatable::Error(reported.into()),
)),
),
(Err(ErrorHandled::TooGeneric(_)), _)
| (_, Err(ErrorHandled::TooGeneric(_))) => {
if c1.has_non_region_infer() || c2.has_non_region_infer() {
@ -660,7 +652,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} else {
// Two different constants using generic parameters ~> error.
let expected_found = ExpectedFound::new(true, c1, c2);
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
expected_found,
TypeError::ConstMismatch(expected_found),
))
@ -741,7 +733,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
Err(selection_err) => {
debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
ProcessResult::Error(FulfillmentErrorCode::SelectionError(selection_err))
ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
}
}
}
@ -793,7 +785,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
project_obligation.with(tcx, project_obligation.predicate),
])),
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
ProcessResult::Error(FulfillmentErrorCode::ProjectionError(e))
ProcessResult::Error(FulfillmentErrorCode::Project(e))
}
}
}