@@ -330,7 +330,7 @@ pub struct HandlerFlags {
330
330
pub can_emit_warnings : bool ,
331
331
/// If true, error-level diagnostics are upgraded to bug-level.
332
332
/// (rustc: see `-Z treat-err-as-bug`)
333
- pub treat_err_as_bug : bool ,
333
+ pub treat_err_as_bug : Option < usize > ,
334
334
/// If true, immediately emit diagnostics that would otherwise be buffered.
335
335
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
336
336
pub dont_buffer_diagnostics : bool ,
@@ -360,7 +360,7 @@ impl Drop for Handler {
360
360
impl Handler {
361
361
pub fn with_tty_emitter ( color_config : ColorConfig ,
362
362
can_emit_warnings : bool ,
363
- treat_err_as_bug : bool ,
363
+ treat_err_as_bug : Option < usize > ,
364
364
cm : Option < Lrc < SourceMapperDyn > > )
365
365
-> Handler {
366
366
Handler :: with_tty_emitter_and_flags (
@@ -382,7 +382,7 @@ impl Handler {
382
382
}
383
383
384
384
pub fn with_emitter ( can_emit_warnings : bool ,
385
- treat_err_as_bug : bool ,
385
+ treat_err_as_bug : Option < usize > ,
386
386
e : Box < dyn Emitter + sync:: Send > )
387
387
-> Handler {
388
388
Handler :: with_emitter_and_flags (
@@ -516,8 +516,20 @@ impl Handler {
516
516
}
517
517
518
518
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) ;
521
533
}
522
534
}
523
535
@@ -558,7 +570,7 @@ impl Handler {
558
570
panic ! ( ExplicitBug ) ;
559
571
}
560
572
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 ( ) {
562
574
// FIXME: don't abort here if report_delayed_bugs is off
563
575
self . span_bug ( sp, msg) ;
564
576
}
@@ -593,14 +605,14 @@ impl Handler {
593
605
DiagnosticBuilder :: new ( self , FailureNote , msg) . emit ( )
594
606
}
595
607
pub fn fatal ( & self , msg : & str ) -> FatalError {
596
- if self . flags . treat_err_as_bug {
608
+ if self . treat_err_as_bug ( ) {
597
609
self . bug ( msg) ;
598
610
}
599
611
DiagnosticBuilder :: new ( self , Fatal , msg) . emit ( ) ;
600
612
FatalError
601
613
}
602
614
pub fn err ( & self , msg : & str ) {
603
- if self . flags . treat_err_as_bug {
615
+ if self . treat_err_as_bug ( ) {
604
616
self . bug ( msg) ;
605
617
}
606
618
let mut db = DiagnosticBuilder :: new ( self , Error , msg) ;
@@ -610,6 +622,9 @@ impl Handler {
610
622
let mut db = DiagnosticBuilder :: new ( self , Warning , msg) ;
611
623
db. emit ( ) ;
612
624
}
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
+ }
613
628
pub fn note_without_error ( & self , msg : & str ) {
614
629
let mut db = DiagnosticBuilder :: new ( self , Note , msg) ;
615
630
db. emit ( ) ;
@@ -624,8 +639,8 @@ impl Handler {
624
639
}
625
640
626
641
fn bump_err_count ( & self ) {
627
- self . panic_if_treat_err_as_bug ( ) ;
628
642
self . err_count . fetch_add ( 1 , SeqCst ) ;
643
+ self . panic_if_treat_err_as_bug ( ) ;
629
644
}
630
645
631
646
pub fn err_count ( & self ) -> usize {
@@ -642,6 +657,9 @@ impl Handler {
642
657
1 => "aborting due to previous error" . to_string ( ) ,
643
658
_ => format ! ( "aborting due to {} previous errors" , self . err_count( ) )
644
659
} ;
660
+ if self . treat_err_as_bug ( ) {
661
+ return ;
662
+ }
645
663
646
664
let _ = self . fatal ( & s) ;
647
665
0 commit comments