From 04c049498d8c24b890bc22f8ee2d541d5e4ee2f6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 14:09:55 -0400 Subject: [PATCH] rename some variants in FulfillmentErrorCode --- .../rustc_borrowck/src/diagnostics/mod.rs | 2 +- .../src/diagnostics/mutability_errors.rs | 2 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 9 ++--- .../src/fn_ctxt/suggestions.rs | 2 +- compiler/rustc_infer/src/traits/mod.rs | 16 ++++----- .../src/traits/structural_impls.rs | 8 ++--- .../src/solve/fulfill.rs | 16 ++++----- .../error_reporting/type_err_ctxt_ext.rs | 17 +++++---- .../src/traits/fulfill.rs | 36 ++++++++----------- 9 files changed, 46 insertions(+), 62 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 0b4018a23ce..88172c62a3b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -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( diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 5d74a01aa20..c5f37200fcc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -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( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 2d98f312f8b..c41ad40aa79 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -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)) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index f00d9d0ae3f..f1b719f24c7 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -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)) = diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index f77a6115861..ce6b3e8f487 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -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>), - SelectionError(SelectionError<'tcx>), - ProjectionError(MismatchedProjectionTypes<'tcx>), - SubtypeError(ExpectedFound>, TypeError<'tcx>), // always comes from a SubtypePredicate - ConstEquateError(ExpectedFound>, TypeError<'tcx>), + Select(SelectionError<'tcx>), + Project(MismatchedProjectionTypes<'tcx>), + Subtype(ExpectedFound>, TypeError<'tcx>), // always comes from a SubtypePredicate + ConstEquate(ExpectedFound>, 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 } diff --git a/compiler/rustc_infer/src/traits/structural_impls.rs b/compiler/rustc_infer/src/traits/structural_impls.rs index 064e09b8750..b616d37e5b5 100644 --- a/compiler/rustc_infer/src/traits/structural_impls.rs +++ b/compiler/rustc_infer/src/traits/structural_impls.rs @@ -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"), diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 39d2ec4417c..f92b1eb88cd 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -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:?}") diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 0989d499497..da2e4ab35d2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -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, diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 1f10cb71543..e3497c646db 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -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)) } } }