Skip to content

Commit 27f5ecc

Browse files
Move FulfillmentErrorCode to rustc_trait_selection too
1 parent 94a524e commit 27f5ecc

File tree

8 files changed

+51
-52
lines changed

8 files changed

+51
-52
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, Namespace};
1111
use rustc_hir::CoroutineKind;
1212
use rustc_index::IndexSlice;
1313
use rustc_infer::infer::BoundRegionConversionTime;
14-
use rustc_infer::traits::{FulfillmentErrorCode, SelectionError};
14+
use rustc_infer::traits::SelectionError;
1515
use rustc_middle::bug;
1616
use rustc_middle::mir::tcx::PlaceTy;
1717
use rustc_middle::mir::{
@@ -29,7 +29,9 @@ use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
2929
use rustc_target::abi::{FieldIdx, VariantIdx};
3030
use rustc_trait_selection::infer::InferCtxtExt;
3131
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
32-
use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions;
32+
use rustc_trait_selection::traits::{
33+
type_known_to_meet_bound_modulo_regions, FulfillmentErrorCode,
34+
};
3335

3436
use crate::fluent_generated as fluent;
3537

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use hir::{ExprKind, Param};
66
use rustc_errors::{Applicability, Diag};
77
use rustc_hir::intravisit::Visitor;
88
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
9-
use rustc_infer::traits;
109
use rustc_middle::bug;
1110
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
1211
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast};
@@ -18,6 +17,7 @@ use rustc_span::symbol::{kw, Symbol};
1817
use rustc_span::{sym, BytePos, DesugaringKind, Span};
1918
use rustc_target::abi::FieldIdx;
2019
use rustc_trait_selection::infer::InferCtxtExt;
20+
use rustc_trait_selection::traits;
2121
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
2222

2323
use crate::diagnostics::BorrowedContentSource;

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_hir::{
2222
};
2323
use rustc_hir_analysis::collect::suggest_impl_trait;
2424
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
25-
use rustc_infer::traits;
2625
use rustc_middle::lint::in_external_macro;
2726
use rustc_middle::middle::stability::EvalResult;
2827
use rustc_middle::span_bug;
@@ -36,6 +35,7 @@ use rustc_span::source_map::Spanned;
3635
use rustc_span::symbol::{sym, Ident};
3736
use rustc_span::{Span, Symbol};
3837
use rustc_trait_selection::infer::InferCtxtExt;
38+
use rustc_trait_selection::traits;
3939
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
4040
use rustc_trait_selection::traits::error_reporting::DefIdOrName;
4141
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;

compiler/rustc_infer/src/traits/mod.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use hir::def_id::LocalDefId;
1515
use rustc_hir as hir;
1616
use rustc_middle::traits::query::NoSolution;
1717
use rustc_middle::traits::solve::Certainty;
18-
use rustc_middle::ty::error::{ExpectedFound, TypeError};
19-
use rustc_middle::ty::{self, Const, Ty, TyCtxt, Upcast};
18+
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
2019
use rustc_span::Span;
2120

2221
pub use self::ImplSource::*;
@@ -124,24 +123,6 @@ pub type Selection<'tcx> = ImplSource<'tcx, PredicateObligation<'tcx>>;
124123
pub type ObligationInspector<'tcx> =
125124
fn(&InferCtxt<'tcx>, &PredicateObligation<'tcx>, Result<Certainty, NoSolution>);
126125

127-
// TODO: Pull this down too
128-
#[derive(Clone)]
129-
pub enum FulfillmentErrorCode<'tcx> {
130-
/// Inherently impossible to fulfill; this trait is implemented if and only
131-
/// if it is already implemented.
132-
Cycle(Vec<PredicateObligation<'tcx>>),
133-
Select(SelectionError<'tcx>),
134-
Project(MismatchedProjectionTypes<'tcx>),
135-
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
136-
ConstEquate(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
137-
Ambiguity {
138-
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
139-
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
140-
/// emitting a fatal error instead.
141-
overflow: Option<bool>,
142-
},
143-
}
144-
145126
impl<'tcx, O> Obligation<'tcx, O> {
146127
pub fn new(
147128
tcx: TyCtxt<'tcx>,

compiler/rustc_infer/src/traits/structural_impls.rs

-21
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
2929
}
3030
}
3131

32-
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
33-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34-
use traits::FulfillmentErrorCode::*;
35-
match *self {
36-
Select(ref e) => write!(f, "{e:?}"),
37-
Project(ref e) => write!(f, "{e:?}"),
38-
Subtype(ref a, ref b) => {
39-
write!(f, "CodeSubtypeError({a:?}, {b:?})")
40-
}
41-
ConstEquate(ref a, ref b) => {
42-
write!(f, "CodeConstEquateError({a:?}, {b:?})")
43-
}
44-
Ambiguity { overflow: None } => write!(f, "Ambiguity"),
45-
Ambiguity { overflow: Some(suggest_increasing_limit) } => {
46-
write!(f, "Overflow({suggest_increasing_limit})")
47-
}
48-
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
49-
}
50-
}
51-
}
52-
5332
impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
5433
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5534
write!(f, "MismatchedProjectionTypes({:?})", self.err)

compiler/rustc_trait_selection/src/solve/fulfill.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ use rustc_infer::infer::InferCtxt;
66
use rustc_infer::traits::query::NoSolution;
77
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
88
use rustc_infer::traits::{
9-
self, FromSolverError, FulfillmentErrorCode, FulfillmentErrorLike, MismatchedProjectionTypes,
10-
Obligation, ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError,
11-
TraitEngine,
9+
self, FromSolverError, FulfillmentErrorLike, MismatchedProjectionTypes, Obligation,
10+
ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError, TraitEngine,
1211
};
1312
use rustc_middle::bug;
1413
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1514
use rustc_middle::ty::{self, TyCtxt};
1615
use rustc_span::symbol::sym;
1716

18-
use crate::traits::{FulfillmentError, ScrubbedTraitError};
17+
use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError};
1918

2019
use super::eval_ctxt::GenerateProofTree;
2120
use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor};

compiler/rustc_trait_selection/src/traits/mod.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
3232
use rustc_errors::ErrorGuaranteed;
3333
use rustc_middle::query::Providers;
3434
use rustc_middle::span_bug;
35+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3536
use rustc_middle::ty::fold::TypeFoldable;
3637
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
3738
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast};
@@ -70,7 +71,7 @@ pub use self::util::{with_replaced_escaping_bound_vars, BoundVarReplacer, Placeh
7071

7172
pub use rustc_infer::traits::*;
7273

73-
/// A trait error without most of its information removed. This is the error
74+
/// A trait error with most of its information removed. This is the error
7475
/// returned by an [`ObligationCtxt`] by default, and suitable if you just
7576
/// want to see if a predicate holds, and don't particularly care about the
7677
/// error itself (except for if it's an ambiguity or true error).
@@ -142,6 +143,43 @@ impl<'tcx> Debug for FulfillmentError<'tcx> {
142143
}
143144
}
144145

146+
#[derive(Clone)]
147+
pub enum FulfillmentErrorCode<'tcx> {
148+
/// Inherently impossible to fulfill; this trait is implemented if and only
149+
/// if it is already implemented.
150+
Cycle(Vec<PredicateObligation<'tcx>>),
151+
Select(SelectionError<'tcx>),
152+
Project(MismatchedProjectionTypes<'tcx>),
153+
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
154+
ConstEquate(ExpectedFound<ty::Const<'tcx>>, TypeError<'tcx>),
155+
Ambiguity {
156+
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
157+
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
158+
/// emitting a fatal error instead.
159+
overflow: Option<bool>,
160+
},
161+
}
162+
163+
impl<'tcx> Debug for FulfillmentErrorCode<'tcx> {
164+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
165+
match *self {
166+
FulfillmentErrorCode::Select(ref e) => write!(f, "{e:?}"),
167+
FulfillmentErrorCode::Project(ref e) => write!(f, "{e:?}"),
168+
FulfillmentErrorCode::Subtype(ref a, ref b) => {
169+
write!(f, "CodeSubtypeError({a:?}, {b:?})")
170+
}
171+
FulfillmentErrorCode::ConstEquate(ref a, ref b) => {
172+
write!(f, "CodeConstEquateError({a:?}, {b:?})")
173+
}
174+
FulfillmentErrorCode::Ambiguity { overflow: None } => write!(f, "Ambiguity"),
175+
FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => {
176+
write!(f, "Overflow({suggest_increasing_limit})")
177+
}
178+
FulfillmentErrorCode::Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
179+
}
180+
}
181+
}
182+
145183
/// Whether to skip the leak check, as part of a future compatibility warning step.
146184
///
147185
/// The "default" for skip-leak-check corresponds to the current

compiler/rustc_traits/src/codegen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// general routines.
55

66
use rustc_infer::infer::TyCtxtInferExt;
7-
use rustc_infer::traits::FulfillmentErrorCode;
87
use rustc_middle::bug;
98
use rustc_middle::traits::CodegenObligationError;
109
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
1110
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
1211
use rustc_trait_selection::traits::{
13-
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext, Unimplemented,
12+
FulfillmentErrorCode, ImplSource, Obligation, ObligationCause, ObligationCtxt,
13+
SelectionContext, Unimplemented,
1414
};
1515
use tracing::debug;
1616

0 commit comments

Comments
 (0)