Skip to content

Commit f37a919

Browse files
Remove redundant Code from FulfillmentErrorCode variants
1 parent 174e73a commit f37a919

File tree

11 files changed

+59
-60
lines changed

11 files changed

+59
-60
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12131213
Applicability::MaybeIncorrect,
12141214
);
12151215
for error in errors {
1216-
if let FulfillmentErrorCode::CodeSelectionError(
1216+
if let FulfillmentErrorCode::SelectionError(
12171217
SelectionError::Unimplemented,
12181218
) = error.code
12191219
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
12881288
}
12891289
// The type doesn't implement Clone because of unmet obligations.
12901290
for error in errors {
1291-
if let traits::FulfillmentErrorCode::CodeSelectionError(
1291+
if let traits::FulfillmentErrorCode::SelectionError(
12921292
traits::SelectionError::Unimplemented,
12931293
) = error.code
12941294
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8686
// Finally, for ambiguity-related errors, we actually want to look
8787
// for a parameter that is the source of the inference type left
8888
// over in this predicate.
89-
if let traits::FulfillmentErrorCode::CodeAmbiguity { .. } = error.code {
89+
if let traits::FulfillmentErrorCode::Ambiguity { .. } = error.code {
9090
fallback_param_to_point_at = None;
9191
self_param_to_point_at = None;
9292
param_to_point_at =
@@ -361,7 +361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361361
error: &traits::FulfillmentError<'tcx>,
362362
span: Span,
363363
) -> bool {
364-
if let traits::FulfillmentErrorCode::CodeSelectionError(
364+
if let traits::FulfillmentErrorCode::SelectionError(
365365
traits::SelectionError::OutputTypeParameterMismatch(
366366
box traits::SelectionOutputTypeParameterMismatch { expected_trait_ref, .. },
367367
),

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481648
}
16491649
}
16501650
for error in errors {
1651-
if let traits::FulfillmentErrorCode::CodeSelectionError(
1651+
if let traits::FulfillmentErrorCode::SelectionError(
16521652
traits::SelectionError::Unimplemented,
16531653
) = error.code
16541654
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =

compiler/rustc_infer/src/traits/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
1717
use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt};
1818
use rustc_span::Span;
1919

20-
pub use self::FulfillmentErrorCode::*;
2120
pub use self::ImplSource::*;
2221
pub use self::SelectionError::*;
2322

@@ -129,12 +128,12 @@ pub struct FulfillmentError<'tcx> {
129128
#[derive(Clone)]
130129
pub enum FulfillmentErrorCode<'tcx> {
131130
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
132-
CodeCycle(Vec<PredicateObligation<'tcx>>),
133-
CodeSelectionError(SelectionError<'tcx>),
134-
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
135-
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
136-
CodeConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
137-
CodeAmbiguity {
131+
Cycle(Vec<PredicateObligation<'tcx>>),
132+
SelectionError(SelectionError<'tcx>),
133+
ProjectionError(MismatchedProjectionTypes<'tcx>),
134+
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
135+
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
136+
Ambiguity {
138137
/// Overflow reported from the new solver `-Znext-solver`, which will
139138
/// be reported as an regular error as opposed to a fatal error.
140139
overflow: bool,

compiler/rustc_infer/src/traits/structural_impls.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
3737

3838
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
3939
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
use traits::FulfillmentErrorCode::*;
4041
match *self {
41-
super::CodeSelectionError(ref e) => write!(f, "{e:?}"),
42-
super::CodeProjectionError(ref e) => write!(f, "{e:?}"),
43-
super::CodeSubtypeError(ref a, ref b) => {
42+
SelectionError(ref e) => write!(f, "{e:?}"),
43+
ProjectionError(ref e) => write!(f, "{e:?}"),
44+
SubtypeError(ref a, ref b) => {
4445
write!(f, "CodeSubtypeError({a:?}, {b:?})")
4546
}
46-
super::CodeConstEquateError(ref a, ref b) => {
47+
ConstEquateError(ref a, ref b) => {
4748
write!(f, "CodeConstEquateError({a:?}, {b:?})")
4849
}
49-
super::CodeAmbiguity { overflow: false } => write!(f, "Ambiguity"),
50-
super::CodeAmbiguity { overflow: true } => write!(f, "Overflow"),
51-
super::CodeCycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
50+
Ambiguity { overflow: false } => write!(f, "Ambiguity"),
51+
Ambiguity { overflow: true } => write!(f, "Overflow"),
52+
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
5253
}
5354
}
5455
}

compiler/rustc_trait_selection/src/solve/fulfill.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
6161
.0
6262
{
6363
Ok((_, Certainty::Maybe(MaybeCause::Ambiguity), _)) => {
64-
FulfillmentErrorCode::CodeAmbiguity { overflow: false }
64+
FulfillmentErrorCode::Ambiguity { overflow: false }
6565
}
6666
Ok((_, Certainty::Maybe(MaybeCause::Overflow), _)) => {
67-
FulfillmentErrorCode::CodeAmbiguity { overflow: true }
67+
FulfillmentErrorCode::Ambiguity { overflow: true }
6868
}
6969
Ok((_, Certainty::Yes, _)) => {
7070
bug!("did not expect successful goal when collecting ambiguity errors")
@@ -103,18 +103,18 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
103103
obligation: obligation.clone(),
104104
code: match goal.predicate.kind().skip_binder() {
105105
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
106-
FulfillmentErrorCode::CodeProjectionError(
106+
FulfillmentErrorCode::ProjectionError(
107107
// FIXME: This could be a `Sorts` if the term is a type
108108
MismatchedProjectionTypes { err: TypeError::Mismatch },
109109
)
110110
}
111111
ty::PredicateKind::NormalizesTo(..) => {
112-
FulfillmentErrorCode::CodeProjectionError(
112+
FulfillmentErrorCode::ProjectionError(
113113
MismatchedProjectionTypes { err: TypeError::Mismatch },
114114
)
115115
}
116116
ty::PredicateKind::AliasRelate(_, _, _) => {
117-
FulfillmentErrorCode::CodeProjectionError(
117+
FulfillmentErrorCode::ProjectionError(
118118
MismatchedProjectionTypes { err: TypeError::Mismatch },
119119
)
120120
}
@@ -123,7 +123,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
123123
goal.predicate.kind().rebind((pred.a, pred.b)),
124124
);
125125
let expected_found = ExpectedFound::new(true, a, b);
126-
FulfillmentErrorCode::CodeSubtypeError(
126+
FulfillmentErrorCode::SubtypeError(
127127
expected_found,
128128
TypeError::Sorts(expected_found),
129129
)
@@ -133,15 +133,15 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
133133
goal.predicate.kind().rebind((pred.a, pred.b)),
134134
);
135135
let expected_found = ExpectedFound::new(false, a, b);
136-
FulfillmentErrorCode::CodeSubtypeError(
136+
FulfillmentErrorCode::SubtypeError(
137137
expected_found,
138138
TypeError::Sorts(expected_found),
139139
)
140140
}
141141
ty::PredicateKind::Clause(_)
142142
| ty::PredicateKind::ObjectSafe(_)
143143
| ty::PredicateKind::Ambiguous => {
144-
FulfillmentErrorCode::CodeSelectionError(
144+
FulfillmentErrorCode::SelectionError(
145145
SelectionError::Unimplemented,
146146
)
147147
}

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
785785

786786
ty::PredicateKind::Subtype(predicate) => {
787787
// Errors for Subtype predicates show up as
788-
// `FulfillmentErrorCode::CodeSubtypeError`,
788+
// `FulfillmentErrorCode::SubtypeError`,
789789
// not selection error.
790790
span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
791791
}
792792

793793
ty::PredicateKind::Coerce(predicate) => {
794794
// Errors for Coerce predicates show up as
795-
// `FulfillmentErrorCode::CodeSubtypeError`,
795+
// `FulfillmentErrorCode::SubtypeError`,
796796
// not selection error.
797797
span_bug!(span, "coerce requirement gave wrong error: `{:?}`", predicate)
798798
}
@@ -1575,23 +1575,23 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15751575
}
15761576

15771577
match error.code {
1578-
FulfillmentErrorCode::CodeSelectionError(ref selection_error) => {
1578+
FulfillmentErrorCode::SelectionError(ref selection_error) => {
15791579
self.report_selection_error(
15801580
error.obligation.clone(),
15811581
&error.root_obligation,
15821582
selection_error,
15831583
);
15841584
}
1585-
FulfillmentErrorCode::CodeProjectionError(ref e) => {
1585+
FulfillmentErrorCode::ProjectionError(ref e) => {
15861586
self.report_projection_error(&error.obligation, e);
15871587
}
1588-
FulfillmentErrorCode::CodeAmbiguity { overflow: false } => {
1588+
FulfillmentErrorCode::Ambiguity { overflow: false } => {
15891589
self.maybe_report_ambiguity(&error.obligation);
15901590
}
1591-
FulfillmentErrorCode::CodeAmbiguity { overflow: true } => {
1591+
FulfillmentErrorCode::Ambiguity { overflow: true } => {
15921592
self.report_overflow_no_abort(error.obligation.clone());
15931593
}
1594-
FulfillmentErrorCode::CodeSubtypeError(ref expected_found, ref err) => {
1594+
FulfillmentErrorCode::SubtypeError(ref expected_found, ref err) => {
15951595
self.report_mismatched_types(
15961596
&error.obligation.cause,
15971597
expected_found.expected,
@@ -1600,7 +1600,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16001600
)
16011601
.emit();
16021602
}
1603-
FulfillmentErrorCode::CodeConstEquateError(ref expected_found, ref err) => {
1603+
FulfillmentErrorCode::ConstEquateError(ref expected_found, ref err) => {
16041604
let mut diag = self.report_mismatched_consts(
16051605
&error.obligation.cause,
16061606
expected_found.expected,
@@ -1625,7 +1625,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16251625
}
16261626
diag.emit();
16271627
}
1628-
FulfillmentErrorCode::CodeCycle(ref cycle) => {
1628+
FulfillmentErrorCode::Cycle(ref cycle) => {
16291629
self.report_overflow_obligation_cycle(cycle);
16301630
}
16311631
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ use super::const_evaluatable;
1818
use super::project::{self, ProjectAndUnifyResult};
1919
use super::select::SelectionContext;
2020
use super::wf;
21-
use super::CodeAmbiguity;
22-
use super::CodeProjectionError;
23-
use super::CodeSelectionError;
2421
use super::EvaluationResult;
2522
use super::PredicateObligation;
2623
use super::Unimplemented;
@@ -135,7 +132,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
135132
_infcx: &InferCtxt<'tcx>,
136133
) -> Vec<FulfillmentError<'tcx>> {
137134
self.predicates
138-
.to_errors(CodeAmbiguity { overflow: false })
135+
.to_errors(FulfillmentErrorCode::Ambiguity { overflow: false })
139136
.into_iter()
140137
.map(to_fulfillment_error)
141138
.collect()
@@ -409,7 +406,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
409406

410407
ty::PredicateKind::ObjectSafe(trait_def_id) => {
411408
if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
412-
ProcessResult::Error(CodeSelectionError(Unimplemented))
409+
ProcessResult::Error(FulfillmentErrorCode::SelectionError(Unimplemented))
413410
} else {
414411
ProcessResult::Changed(vec![])
415412
}
@@ -480,7 +477,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
480477
Ok(Err(err)) => {
481478
let expected_found =
482479
ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
483-
ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
480+
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
484481
expected_found,
485482
err,
486483
))
@@ -503,7 +500,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
503500
Ok(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
504501
Ok(Err(err)) => {
505502
let expected_found = ExpectedFound::new(false, coerce.a, coerce.b);
506-
ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
503+
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
507504
expected_found,
508505
err,
509506
))
@@ -529,7 +526,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
529526
Err(
530527
e @ NotConstEvaluatable::MentionsParam
531528
| e @ NotConstEvaluatable::Error(_),
532-
) => ProcessResult::Error(CodeSelectionError(
529+
) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
533530
SelectionError::NotConstEvaluatable(e),
534531
)),
535532
}
@@ -618,28 +615,30 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
618615
Ok(inf_ok) => {
619616
ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
620617
}
621-
Err(err) => ProcessResult::Error(
622-
FulfillmentErrorCode::CodeConstEquateError(
618+
Err(err) => {
619+
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
623620
ExpectedFound::new(true, c1, c2),
624621
err,
625-
),
626-
),
622+
))
623+
}
627624
}
628625
}
629626
(Err(ErrorHandled::Reported(reported, _)), _)
630-
| (_, Err(ErrorHandled::Reported(reported, _))) => ProcessResult::Error(
631-
CodeSelectionError(SelectionError::NotConstEvaluatable(
632-
NotConstEvaluatable::Error(reported.into()),
633-
)),
634-
),
627+
| (_, Err(ErrorHandled::Reported(reported, _))) => {
628+
ProcessResult::Error(FulfillmentErrorCode::SelectionError(
629+
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(
630+
reported.into(),
631+
)),
632+
))
633+
}
635634
(Err(ErrorHandled::TooGeneric(_)), _)
636635
| (_, Err(ErrorHandled::TooGeneric(_))) => {
637636
if c1.has_non_region_infer() || c2.has_non_region_infer() {
638637
ProcessResult::Unchanged
639638
} else {
640639
// Two different constants using generic parameters ~> error.
641640
let expected_found = ExpectedFound::new(true, c1, c2);
642-
ProcessResult::Error(FulfillmentErrorCode::CodeConstEquateError(
641+
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
643642
expected_found,
644643
TypeError::ConstMismatch(expected_found),
645644
))
@@ -654,7 +653,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
654653
ty,
655654
) {
656655
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
657-
Err(_) => ProcessResult::Error(FulfillmentErrorCode::CodeSelectionError(
656+
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
658657
SelectionError::Unimplemented,
659658
)),
660659
}
@@ -677,7 +676,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
677676
Ok(())
678677
} else {
679678
let cycle: Vec<_> = cycle.map(|c| c.obligation.clone()).collect();
680-
Err(FulfillmentErrorCode::CodeCycle(cycle))
679+
Err(FulfillmentErrorCode::Cycle(cycle))
681680
}
682681
}
683682
}
@@ -732,7 +731,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
732731
Err(selection_err) => {
733732
debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
734733

735-
ProcessResult::Error(CodeSelectionError(selection_err))
734+
ProcessResult::Error(FulfillmentErrorCode::SelectionError(selection_err))
736735
}
737736
}
738737
}
@@ -784,7 +783,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
784783
project_obligation.with(tcx, project_obligation.predicate),
785784
])),
786785
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
787-
ProcessResult::Error(CodeProjectionError(e))
786+
ProcessResult::Error(FulfillmentErrorCode::ProjectionError(e))
788787
}
789788
}
790789
}

0 commit comments

Comments
 (0)