@@ -233,11 +233,10 @@ pub use diagnostic_builder::DiagnosticBuilder;
233
233
/// (fatal, bug, unimpl) may cause immediate exit,
234
234
/// others log errors for later reporting.
235
235
pub struct Handler {
236
+ pub flags : HandlerFlags ,
237
+
236
238
err_count : Cell < usize > ,
237
239
emitter : RefCell < Box < Emitter > > ,
238
- pub can_emit_warnings : bool ,
239
- treat_err_as_bug : bool ,
240
- pub macro_backtrace : bool ,
241
240
continue_after_error : Cell < bool > ,
242
241
delayed_span_bug : RefCell < Option < Diagnostic > > ,
243
242
tracked_diagnostics : RefCell < Option < Vec < Diagnostic > > > ,
@@ -248,28 +247,55 @@ pub struct Handler {
248
247
emitted_diagnostics : RefCell < FxHashSet < u128 > > ,
249
248
}
250
249
250
+ #[ derive( Default ) ]
251
+ pub struct HandlerFlags {
252
+ pub can_emit_warnings : bool ,
253
+ pub treat_err_as_bug : bool ,
254
+ pub external_macro_backtrace : bool ,
255
+ }
256
+
251
257
impl Handler {
252
258
pub fn with_tty_emitter ( color_config : ColorConfig ,
253
259
can_emit_warnings : bool ,
254
260
treat_err_as_bug : bool ,
255
- macro_backtrace : bool ,
256
261
cm : Option < Rc < CodeMapper > > )
257
262
-> Handler {
263
+ Handler :: with_tty_emitter_and_flags (
264
+ color_config,
265
+ cm,
266
+ HandlerFlags {
267
+ can_emit_warnings,
268
+ treat_err_as_bug,
269
+ .. Default :: default ( )
270
+ } )
271
+ }
272
+
273
+ pub fn with_tty_emitter_and_flags ( color_config : ColorConfig ,
274
+ cm : Option < Rc < CodeMapper > > ,
275
+ flags : HandlerFlags )
276
+ -> Handler {
258
277
let emitter = Box :: new ( EmitterWriter :: stderr ( color_config, cm, false ) ) ;
259
- Handler :: with_emitter ( can_emit_warnings , treat_err_as_bug , macro_backtrace , emitter )
278
+ Handler :: with_emitter_and_flags ( emitter , flags )
260
279
}
261
280
262
281
pub fn with_emitter ( can_emit_warnings : bool ,
263
282
treat_err_as_bug : bool ,
264
- macro_backtrace : bool ,
265
283
e : Box < Emitter > )
266
284
-> Handler {
285
+ Handler :: with_emitter_and_flags (
286
+ e,
287
+ HandlerFlags {
288
+ can_emit_warnings,
289
+ treat_err_as_bug,
290
+ .. Default :: default ( )
291
+ } )
292
+ }
293
+
294
+ pub fn with_emitter_and_flags ( e : Box < Emitter > , flags : HandlerFlags ) -> Handler {
267
295
Handler {
296
+ flags,
268
297
err_count : Cell :: new ( 0 ) ,
269
298
emitter : RefCell :: new ( e) ,
270
- can_emit_warnings,
271
- treat_err_as_bug,
272
- macro_backtrace,
273
299
continue_after_error : Cell :: new ( true ) ,
274
300
delayed_span_bug : RefCell :: new ( None ) ,
275
301
tracked_diagnostics : RefCell :: new ( None ) ,
@@ -297,7 +323,7 @@ impl Handler {
297
323
-> DiagnosticBuilder < ' a > {
298
324
let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
299
325
result. set_span ( sp) ;
300
- if !self . can_emit_warnings {
326
+ if !self . flags . can_emit_warnings {
301
327
result. cancel ( ) ;
302
328
}
303
329
result
@@ -310,14 +336,14 @@ impl Handler {
310
336
let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
311
337
result. set_span ( sp) ;
312
338
result. code ( code) ;
313
- if !self . can_emit_warnings {
339
+ if !self . flags . can_emit_warnings {
314
340
result. cancel ( ) ;
315
341
}
316
342
result
317
343
}
318
344
pub fn struct_warn < ' a > ( & ' a self , msg : & str ) -> DiagnosticBuilder < ' a > {
319
345
let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
320
- if !self . can_emit_warnings {
346
+ if !self . flags . can_emit_warnings {
321
347
result. cancel ( ) ;
322
348
}
323
349
result
@@ -380,7 +406,7 @@ impl Handler {
380
406
}
381
407
382
408
fn panic_if_treat_err_as_bug ( & self ) {
383
- if self . treat_err_as_bug {
409
+ if self . flags . treat_err_as_bug {
384
410
panic ! ( "encountered error with `-Z treat_err_as_bug" ) ;
385
411
}
386
412
}
@@ -422,7 +448,7 @@ impl Handler {
422
448
panic ! ( ExplicitBug ) ;
423
449
}
424
450
pub fn delay_span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
425
- if self . treat_err_as_bug {
451
+ if self . flags . treat_err_as_bug {
426
452
self . span_bug ( sp, msg) ;
427
453
}
428
454
let mut diagnostic = Diagnostic :: new ( Level :: Bug , msg) ;
@@ -447,15 +473,15 @@ impl Handler {
447
473
self . span_bug ( sp, & format ! ( "unimplemented {}" , msg) ) ;
448
474
}
449
475
pub fn fatal ( & self , msg : & str ) -> FatalError {
450
- if self . treat_err_as_bug {
476
+ if self . flags . treat_err_as_bug {
451
477
self . bug ( msg) ;
452
478
}
453
479
let mut db = DiagnosticBuilder :: new ( self , Fatal , msg) ;
454
480
db. emit ( ) ;
455
481
FatalError
456
482
}
457
483
pub fn err ( & self , msg : & str ) {
458
- if self . treat_err_as_bug {
484
+ if self . flags . treat_err_as_bug {
459
485
self . bug ( msg) ;
460
486
}
461
487
let mut db = DiagnosticBuilder :: new ( self , Error , msg) ;
@@ -508,7 +534,7 @@ impl Handler {
508
534
panic ! ( self . fatal( & s) ) ;
509
535
}
510
536
pub fn emit ( & self , msp : & MultiSpan , msg : & str , lvl : Level ) {
511
- if lvl == Warning && !self . can_emit_warnings {
537
+ if lvl == Warning && !self . flags . can_emit_warnings {
512
538
return ;
513
539
}
514
540
let mut db = DiagnosticBuilder :: new ( self , lvl, msg) ;
@@ -519,7 +545,7 @@ impl Handler {
519
545
}
520
546
}
521
547
pub fn emit_with_code ( & self , msp : & MultiSpan , msg : & str , code : DiagnosticId , lvl : Level ) {
522
- if lvl == Warning && !self . can_emit_warnings {
548
+ if lvl == Warning && !self . flags . can_emit_warnings {
523
549
return ;
524
550
}
525
551
let mut db = DiagnosticBuilder :: new_with_code ( self , lvl, Some ( code) , msg) ;
0 commit comments