@@ -330,7 +330,7 @@ pub struct HandlerFlags {
330330 pub can_emit_warnings : bool ,
331331 /// If true, error-level diagnostics are upgraded to bug-level.
332332 /// (rustc: see `-Z treat-err-as-bug`)
333- pub treat_err_as_bug : bool ,
333+ pub treat_err_as_bug : Option < usize > ,
334334 /// If true, immediately emit diagnostics that would otherwise be buffered.
335335 /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
336336 pub dont_buffer_diagnostics : bool ,
@@ -360,7 +360,7 @@ impl Drop for Handler {
360360impl Handler {
361361 pub fn with_tty_emitter ( color_config : ColorConfig ,
362362 can_emit_warnings : bool ,
363- treat_err_as_bug : bool ,
363+ treat_err_as_bug : Option < usize > ,
364364 cm : Option < Lrc < SourceMapperDyn > > )
365365 -> Handler {
366366 Handler :: with_tty_emitter_and_flags (
@@ -382,7 +382,7 @@ impl Handler {
382382 }
383383
384384 pub fn with_emitter ( can_emit_warnings : bool ,
385- treat_err_as_bug : bool ,
385+ treat_err_as_bug : Option < usize > ,
386386 e : Box < dyn Emitter + sync:: Send > )
387387 -> Handler {
388388 Handler :: with_emitter_and_flags (
@@ -516,8 +516,20 @@ impl Handler {
516516 }
517517
518518 fn panic_if_treat_err_as_bug ( & self ) {
519- if self . flags . treat_err_as_bug {
520- panic ! ( "encountered error with `-Z treat_err_as_bug" ) ;
519+ if self . treat_err_as_bug ( ) {
520+ let s = match ( self . err_count ( ) , self . flags . treat_err_as_bug . unwrap_or ( 0 ) ) {
521+ ( 0 , _) => return ,
522+ ( 1 , 1 ) => "aborting due to `-Z treat-err-as-bug=1`" . to_string ( ) ,
523+ ( 1 , _) => return ,
524+ ( count, as_bug) => {
525+ format ! (
526+ "aborting after {} errors due to `-Z treat-err-as-bug={}`" ,
527+ count,
528+ as_bug,
529+ )
530+ }
531+ } ;
532+ panic ! ( s) ;
521533 }
522534 }
523535
@@ -558,7 +570,7 @@ impl Handler {
558570 panic ! ( ExplicitBug ) ;
559571 }
560572 pub fn delay_span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
561- if self . flags . treat_err_as_bug {
573+ if self . treat_err_as_bug ( ) {
562574 // FIXME: don't abort here if report_delayed_bugs is off
563575 self . span_bug ( sp, msg) ;
564576 }
@@ -593,14 +605,14 @@ impl Handler {
593605 DiagnosticBuilder :: new ( self , FailureNote , msg) . emit ( )
594606 }
595607 pub fn fatal ( & self , msg : & str ) -> FatalError {
596- if self . flags . treat_err_as_bug {
608+ if self . treat_err_as_bug ( ) {
597609 self . bug ( msg) ;
598610 }
599611 DiagnosticBuilder :: new ( self , Fatal , msg) . emit ( ) ;
600612 FatalError
601613 }
602614 pub fn err ( & self , msg : & str ) {
603- if self . flags . treat_err_as_bug {
615+ if self . treat_err_as_bug ( ) {
604616 self . bug ( msg) ;
605617 }
606618 let mut db = DiagnosticBuilder :: new ( self , Error , msg) ;
@@ -610,6 +622,9 @@ impl Handler {
610622 let mut db = DiagnosticBuilder :: new ( self , Warning , msg) ;
611623 db. emit ( ) ;
612624 }
625+ fn treat_err_as_bug ( & self ) -> bool {
626+ self . flags . treat_err_as_bug . map ( |c| self . err_count ( ) >= c) . unwrap_or ( false )
627+ }
613628 pub fn note_without_error ( & self , msg : & str ) {
614629 let mut db = DiagnosticBuilder :: new ( self , Note , msg) ;
615630 db. emit ( ) ;
@@ -624,8 +639,8 @@ impl Handler {
624639 }
625640
626641 fn bump_err_count ( & self ) {
627- self . panic_if_treat_err_as_bug ( ) ;
628642 self . err_count . fetch_add ( 1 , SeqCst ) ;
643+ self . panic_if_treat_err_as_bug ( ) ;
629644 }
630645
631646 pub fn err_count ( & self ) -> usize {
@@ -642,6 +657,9 @@ impl Handler {
642657 1 => "aborting due to previous error" . to_string ( ) ,
643658 _ => format ! ( "aborting due to {} previous errors" , self . err_count( ) )
644659 } ;
660+ if self . treat_err_as_bug ( ) {
661+ return ;
662+ }
645663
646664 let _ = self . fatal ( & s) ;
647665
0 commit comments