@@ -32,6 +32,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
32
32
use rustc_errors:: ErrorGuaranteed ;
33
33
use rustc_middle:: query:: Providers ;
34
34
use rustc_middle:: span_bug;
35
+ use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
35
36
use rustc_middle:: ty:: fold:: TypeFoldable ;
36
37
use rustc_middle:: ty:: visit:: { TypeVisitable , TypeVisitableExt } ;
37
38
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFolder , TypeSuperVisitable , Upcast } ;
@@ -73,7 +74,7 @@ pub use self::util::{with_replaced_escaping_bound_vars, BoundVarReplacer, Placeh
73
74
74
75
pub use rustc_infer:: traits:: * ;
75
76
76
- /// A trait error without most of its information removed. This is the error
77
+ /// A trait error with most of its information removed. This is the error
77
78
/// returned by an [`ObligationCtxt`] by default, and suitable if you just
78
79
/// want to see if a predicate holds, and don't particularly care about the
79
80
/// error itself (except for if it's an ambiguity or true error).
@@ -145,6 +146,43 @@ impl<'tcx> Debug for FulfillmentError<'tcx> {
145
146
}
146
147
}
147
148
149
+ #[ derive( Clone ) ]
150
+ pub enum FulfillmentErrorCode < ' tcx > {
151
+ /// Inherently impossible to fulfill; this trait is implemented if and only
152
+ /// if it is already implemented.
153
+ Cycle ( Vec < PredicateObligation < ' tcx > > ) ,
154
+ Select ( SelectionError < ' tcx > ) ,
155
+ Project ( MismatchedProjectionTypes < ' tcx > ) ,
156
+ Subtype ( ExpectedFound < Ty < ' tcx > > , TypeError < ' tcx > ) , // always comes from a SubtypePredicate
157
+ ConstEquate ( ExpectedFound < ty:: Const < ' tcx > > , TypeError < ' tcx > ) ,
158
+ Ambiguity {
159
+ /// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
160
+ /// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
161
+ /// emitting a fatal error instead.
162
+ overflow : Option < bool > ,
163
+ } ,
164
+ }
165
+
166
+ impl < ' tcx > Debug for FulfillmentErrorCode < ' tcx > {
167
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
168
+ match * self {
169
+ FulfillmentErrorCode :: Select ( ref e) => write ! ( f, "{e:?}" ) ,
170
+ FulfillmentErrorCode :: Project ( ref e) => write ! ( f, "{e:?}" ) ,
171
+ FulfillmentErrorCode :: Subtype ( ref a, ref b) => {
172
+ write ! ( f, "CodeSubtypeError({a:?}, {b:?})" )
173
+ }
174
+ FulfillmentErrorCode :: ConstEquate ( ref a, ref b) => {
175
+ write ! ( f, "CodeConstEquateError({a:?}, {b:?})" )
176
+ }
177
+ FulfillmentErrorCode :: Ambiguity { overflow : None } => write ! ( f, "Ambiguity" ) ,
178
+ FulfillmentErrorCode :: Ambiguity { overflow : Some ( suggest_increasing_limit) } => {
179
+ write ! ( f, "Overflow({suggest_increasing_limit})" )
180
+ }
181
+ FulfillmentErrorCode :: Cycle ( ref cycle) => write ! ( f, "Cycle({cycle:?})" ) ,
182
+ }
183
+ }
184
+ }
185
+
148
186
/// Whether to skip the leak check, as part of a future compatibility warning step.
149
187
///
150
188
/// The "default" for skip-leak-check corresponds to the current
0 commit comments