@@ -12,6 +12,7 @@ use super::{
12
12
FulfillmentError ,
13
13
FulfillmentErrorCode ,
14
14
MismatchedProjectionTypes ,
15
+ Obligation ,
15
16
ObligationCauseCode ,
16
17
OutputTypeParameterMismatch ,
17
18
PredicateObligation ,
@@ -21,6 +22,7 @@ use super::{
21
22
use fmt_macros:: { Parser , Piece , Position } ;
22
23
use middle:: infer:: InferCtxt ;
23
24
use middle:: ty:: { self , AsPredicate , ReferencesError , ToPolyTraitRef , TraitRef } ;
25
+ use middle:: ty_fold:: TypeFoldable ;
24
26
use std:: collections:: HashMap ;
25
27
use syntax:: codemap:: { DUMMY_SP , Span } ;
26
28
use syntax:: attr:: { AttributeMethods , AttrMetaMethods } ;
@@ -137,24 +139,36 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
137
139
report
138
140
}
139
141
142
+ /// Reports that an overflow has occurred and halts compilation. We
143
+ /// halt compilation unconditionally because it is important that
144
+ /// overflows never be masked -- they basically represent computations
145
+ /// whose result could not be truly determined and thus we can't say
146
+ /// if the program type checks or not -- and they are unusual
147
+ /// occurrences in any case.
148
+ pub fn report_overflow_error < ' a , ' tcx , T > ( infcx : & InferCtxt < ' a , ' tcx > ,
149
+ obligation : & Obligation < ' tcx , T > )
150
+ -> !
151
+ where T : UserString < ' tcx > + TypeFoldable < ' tcx >
152
+ {
153
+ let predicate =
154
+ infcx. resolve_type_vars_if_possible ( & obligation. predicate ) ;
155
+ span_err ! ( infcx. tcx. sess, obligation. cause. span, E0275 ,
156
+ "overflow evaluating the requirement `{}`" ,
157
+ predicate. user_string( infcx. tcx) ) ;
158
+
159
+ suggest_new_overflow_limit ( infcx. tcx , obligation. cause . span ) ;
160
+
161
+ note_obligation_cause ( infcx, obligation) ;
162
+
163
+ infcx. tcx . sess . abort_if_errors ( ) ;
164
+ unreachable ! ( ) ;
165
+ }
166
+
140
167
pub fn report_selection_error < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
141
168
obligation : & PredicateObligation < ' tcx > ,
142
169
error : & SelectionError < ' tcx > )
143
170
{
144
171
match * error {
145
- SelectionError :: Overflow => {
146
- // We could track the stack here more precisely if we wanted, I imagine.
147
- let predicate =
148
- infcx. resolve_type_vars_if_possible ( & obligation. predicate ) ;
149
- span_err ! ( infcx. tcx. sess, obligation. cause. span, E0275 ,
150
- "overflow evaluating the requirement `{}`" ,
151
- predicate. user_string( infcx. tcx) ) ;
152
-
153
- suggest_new_overflow_limit ( infcx. tcx , obligation. cause . span ) ;
154
-
155
- note_obligation_cause ( infcx, obligation) ;
156
- }
157
-
158
172
SelectionError :: Unimplemented => {
159
173
match & obligation. cause . code {
160
174
& ObligationCauseCode :: CompareImplMethodObligation => {
@@ -309,19 +323,21 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
309
323
}
310
324
}
311
325
312
- fn note_obligation_cause < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
313
- obligation : & PredicateObligation < ' tcx > )
326
+ fn note_obligation_cause < ' a , ' tcx , T > ( infcx : & InferCtxt < ' a , ' tcx > ,
327
+ obligation : & Obligation < ' tcx , T > )
328
+ where T : UserString < ' tcx >
314
329
{
315
330
note_obligation_cause_code ( infcx,
316
331
& obligation. predicate ,
317
332
obligation. cause . span ,
318
333
& obligation. cause . code ) ;
319
334
}
320
335
321
- fn note_obligation_cause_code < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
322
- predicate : & ty:: Predicate < ' tcx > ,
323
- cause_span : Span ,
324
- cause_code : & ObligationCauseCode < ' tcx > )
336
+ fn note_obligation_cause_code < ' a , ' tcx , T > ( infcx : & InferCtxt < ' a , ' tcx > ,
337
+ predicate : & T ,
338
+ cause_span : Span ,
339
+ cause_code : & ObligationCauseCode < ' tcx > )
340
+ where T : UserString < ' tcx >
325
341
{
326
342
let tcx = infcx. tcx ;
327
343
match * cause_code {
0 commit comments