@@ -233,11 +233,10 @@ pub use diagnostic_builder::DiagnosticBuilder;
233233/// (fatal, bug, unimpl) may cause immediate exit,
234234/// others log errors for later reporting.
235235pub struct Handler {
236+ pub flags : HandlerFlags ,
237+
236238 err_count : Cell < usize > ,
237239 emitter : RefCell < Box < Emitter > > ,
238- pub can_emit_warnings : bool ,
239- treat_err_as_bug : bool ,
240- pub macro_backtrace : bool ,
241240 continue_after_error : Cell < bool > ,
242241 delayed_span_bug : RefCell < Option < Diagnostic > > ,
243242 tracked_diagnostics : RefCell < Option < Vec < Diagnostic > > > ,
@@ -248,28 +247,55 @@ pub struct Handler {
248247 emitted_diagnostics : RefCell < FxHashSet < u128 > > ,
249248}
250249
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+
251257impl Handler {
252258 pub fn with_tty_emitter ( color_config : ColorConfig ,
253259 can_emit_warnings : bool ,
254260 treat_err_as_bug : bool ,
255- macro_backtrace : bool ,
256261 cm : Option < Rc < CodeMapper > > )
257262 -> 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 {
258277 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 )
260279 }
261280
262281 pub fn with_emitter ( can_emit_warnings : bool ,
263282 treat_err_as_bug : bool ,
264- macro_backtrace : bool ,
265283 e : Box < Emitter > )
266284 -> 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 {
267295 Handler {
296+ flags,
268297 err_count : Cell :: new ( 0 ) ,
269298 emitter : RefCell :: new ( e) ,
270- can_emit_warnings,
271- treat_err_as_bug,
272- macro_backtrace,
273299 continue_after_error : Cell :: new ( true ) ,
274300 delayed_span_bug : RefCell :: new ( None ) ,
275301 tracked_diagnostics : RefCell :: new ( None ) ,
@@ -297,7 +323,7 @@ impl Handler {
297323 -> DiagnosticBuilder < ' a > {
298324 let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
299325 result. set_span ( sp) ;
300- if !self . can_emit_warnings {
326+ if !self . flags . can_emit_warnings {
301327 result. cancel ( ) ;
302328 }
303329 result
@@ -310,14 +336,14 @@ impl Handler {
310336 let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
311337 result. set_span ( sp) ;
312338 result. code ( code) ;
313- if !self . can_emit_warnings {
339+ if !self . flags . can_emit_warnings {
314340 result. cancel ( ) ;
315341 }
316342 result
317343 }
318344 pub fn struct_warn < ' a > ( & ' a self , msg : & str ) -> DiagnosticBuilder < ' a > {
319345 let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
320- if !self . can_emit_warnings {
346+ if !self . flags . can_emit_warnings {
321347 result. cancel ( ) ;
322348 }
323349 result
@@ -380,7 +406,7 @@ impl Handler {
380406 }
381407
382408 fn panic_if_treat_err_as_bug ( & self ) {
383- if self . treat_err_as_bug {
409+ if self . flags . treat_err_as_bug {
384410 panic ! ( "encountered error with `-Z treat_err_as_bug" ) ;
385411 }
386412 }
@@ -422,7 +448,7 @@ impl Handler {
422448 panic ! ( ExplicitBug ) ;
423449 }
424450 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 {
426452 self . span_bug ( sp, msg) ;
427453 }
428454 let mut diagnostic = Diagnostic :: new ( Level :: Bug , msg) ;
@@ -447,15 +473,15 @@ impl Handler {
447473 self . span_bug ( sp, & format ! ( "unimplemented {}" , msg) ) ;
448474 }
449475 pub fn fatal ( & self , msg : & str ) -> FatalError {
450- if self . treat_err_as_bug {
476+ if self . flags . treat_err_as_bug {
451477 self . bug ( msg) ;
452478 }
453479 let mut db = DiagnosticBuilder :: new ( self , Fatal , msg) ;
454480 db. emit ( ) ;
455481 FatalError
456482 }
457483 pub fn err ( & self , msg : & str ) {
458- if self . treat_err_as_bug {
484+ if self . flags . treat_err_as_bug {
459485 self . bug ( msg) ;
460486 }
461487 let mut db = DiagnosticBuilder :: new ( self , Error , msg) ;
@@ -508,7 +534,7 @@ impl Handler {
508534 panic ! ( self . fatal( & s) ) ;
509535 }
510536 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 {
512538 return ;
513539 }
514540 let mut db = DiagnosticBuilder :: new ( self , lvl, msg) ;
@@ -519,7 +545,7 @@ impl Handler {
519545 }
520546 }
521547 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 {
523549 return ;
524550 }
525551 let mut db = DiagnosticBuilder :: new_with_code ( self , lvl, Some ( code) , msg) ;
0 commit comments