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, Applicability::MaybeIncorrect,
); );
for error in errors { for error in errors {
if let FulfillmentErrorCode::SelectionError( if let FulfillmentErrorCode::Select(
SelectionError::Unimplemented, SelectionError::Unimplemented,
) = error.code ) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait( && 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. // The type doesn't implement Clone because of unmet obligations.
for error in errors { for error in errors {
if let traits::FulfillmentErrorCode::SelectionError( if let traits::FulfillmentErrorCode::Select(
traits::SelectionError::Unimplemented, traits::SelectionError::Unimplemented,
) = error.code ) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait( && let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

View file

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

View file

@ -1700,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
for error in errors { for error in errors {
if let traits::FulfillmentErrorCode::SelectionError( if let traits::FulfillmentErrorCode::Select(
traits::SelectionError::Unimplemented, traits::SelectionError::Unimplemented,
) = error.code ) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) = && 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 /// Inherently impossible to fulfill; this trait is implemented if and only
/// if it is already implemented. /// if it is already implemented.
Cycle(Vec<PredicateObligation<'tcx>>), Cycle(Vec<PredicateObligation<'tcx>>),
SelectionError(SelectionError<'tcx>), Select(SelectionError<'tcx>),
ProjectionError(MismatchedProjectionTypes<'tcx>), Project(MismatchedProjectionTypes<'tcx>),
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>), ConstEquate(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
Ambiguity { Ambiguity {
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation /// 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 /// 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 { pub fn is_true_error(&self) -> bool {
match self.code { match self.code {
FulfillmentErrorCode::SelectionError(_) FulfillmentErrorCode::Select(_)
| FulfillmentErrorCode::ProjectionError(_) | FulfillmentErrorCode::Project(_)
| FulfillmentErrorCode::SubtypeError(_, _) | FulfillmentErrorCode::Subtype(_, _)
| FulfillmentErrorCode::ConstEquateError(_, _) => true, | FulfillmentErrorCode::ConstEquate(_, _) => true,
FulfillmentErrorCode::Cycle(_) | FulfillmentErrorCode::Ambiguity { overflow: _ } => { FulfillmentErrorCode::Cycle(_) | FulfillmentErrorCode::Ambiguity { overflow: _ } => {
false false
} }

View file

@ -39,12 +39,12 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use traits::FulfillmentErrorCode::*; use traits::FulfillmentErrorCode::*;
match *self { match *self {
SelectionError(ref e) => write!(f, "{e:?}"), Select(ref e) => write!(f, "{e:?}"),
ProjectionError(ref e) => write!(f, "{e:?}"), Project(ref e) => write!(f, "{e:?}"),
SubtypeError(ref a, ref b) => { Subtype(ref a, ref b) => {
write!(f, "CodeSubtypeError({a:?}, {b:?})") write!(f, "CodeSubtypeError({a:?}, {b:?})")
} }
ConstEquateError(ref a, ref b) => { ConstEquate(ref a, ref b) => {
write!(f, "CodeConstEquateError({a:?}, {b:?})") write!(f, "CodeConstEquateError({a:?}, {b:?})")
} }
Ambiguity { overflow: None } => write!(f, "Ambiguity"), 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() { let code = match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => { ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
FulfillmentErrorCode::ProjectionError( FulfillmentErrorCode::Project(
// FIXME: This could be a `Sorts` if the term is a type // FIXME: This could be a `Sorts` if the term is a type
MismatchedProjectionTypes { err: TypeError::Mismatch }, MismatchedProjectionTypes { err: TypeError::Mismatch },
) )
} }
ty::PredicateKind::NormalizesTo(..) => { ty::PredicateKind::NormalizesTo(..) => {
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes { FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
err: TypeError::Mismatch,
})
} }
ty::PredicateKind::AliasRelate(_, _, _) => { ty::PredicateKind::AliasRelate(_, _, _) => {
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes { FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
err: TypeError::Mismatch,
})
} }
ty::PredicateKind::Subtype(pred) => { ty::PredicateKind::Subtype(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe( let (a, b) = infcx.enter_forall_and_leak_universe(
obligation.predicate.kind().rebind((pred.a, pred.b)), obligation.predicate.kind().rebind((pred.a, pred.b)),
); );
let expected_found = ExpectedFound::new(true, a, 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) => { ty::PredicateKind::Coerce(pred) => {
let (a, b) = infcx.enter_forall_and_leak_universe( let (a, b) = infcx.enter_forall_and_leak_universe(
obligation.predicate.kind().rebind((pred.a, pred.b)), obligation.predicate.kind().rebind((pred.a, pred.b)),
); );
let expected_found = ExpectedFound::new(false, a, 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::Clause(_)
| ty::PredicateKind::ObjectSafe(_) | ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::Ambiguous => { | ty::PredicateKind::Ambiguous => {
FulfillmentErrorCode::SelectionError(SelectionError::Unimplemented) FulfillmentErrorCode::Select(SelectionError::Unimplemented)
} }
ty::PredicateKind::ConstEquate(..) => { ty::PredicateKind::ConstEquate(..) => {
bug!("unexpected goal: {obligation:?}") bug!("unexpected goal: {obligation:?}")

View file

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

View file

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