@@ -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,7 +516,7 @@ impl Handler {
516
516
}
517
517
518
518
fn panic_if_treat_err_as_bug ( & self ) {
519
- if self . flags . treat_err_as_bug {
519
+ if self . treat_err_as_bug ( ) {
520
520
panic ! ( "encountered error with `-Z treat_err_as_bug" ) ;
521
521
}
522
522
}
@@ -558,7 +558,7 @@ impl Handler {
558
558
panic ! ( ExplicitBug ) ;
559
559
}
560
560
pub fn delay_span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
561
- if self . flags . treat_err_as_bug {
561
+ if self . treat_err_as_bug ( ) {
562
562
// FIXME: don't abort here if report_delayed_bugs is off
563
563
self . span_bug ( sp, msg) ;
564
564
}
@@ -593,14 +593,14 @@ impl Handler {
593
593
DiagnosticBuilder :: new ( self , FailureNote , msg) . emit ( )
594
594
}
595
595
pub fn fatal ( & self , msg : & str ) -> FatalError {
596
- if self . flags . treat_err_as_bug {
596
+ if self . treat_err_as_bug ( ) {
597
597
self . bug ( msg) ;
598
598
}
599
599
DiagnosticBuilder :: new ( self , Fatal , msg) . emit ( ) ;
600
600
FatalError
601
601
}
602
602
pub fn err ( & self , msg : & str ) {
603
- if self . flags . treat_err_as_bug {
603
+ if self . treat_err_as_bug ( ) {
604
604
self . bug ( msg) ;
605
605
}
606
606
let mut db = DiagnosticBuilder :: new ( self , Error , msg) ;
@@ -610,6 +610,9 @@ impl Handler {
610
610
let mut db = DiagnosticBuilder :: new ( self , Warning , msg) ;
611
611
db. emit ( ) ;
612
612
}
613
+ fn treat_err_as_bug ( & self ) -> bool {
614
+ self . flags . treat_err_as_bug . map ( |c| self . err_count ( ) >= c) . unwrap_or ( false )
615
+ }
613
616
pub fn note_without_error ( & self , msg : & str ) {
614
617
let mut db = DiagnosticBuilder :: new ( self , Note , msg) ;
615
618
db. emit ( ) ;
@@ -624,8 +627,8 @@ impl Handler {
624
627
}
625
628
626
629
fn bump_err_count ( & self ) {
627
- self . panic_if_treat_err_as_bug ( ) ;
628
630
self . err_count . fetch_add ( 1 , SeqCst ) ;
631
+ self . panic_if_treat_err_as_bug ( ) ;
629
632
}
630
633
631
634
pub fn err_count ( & self ) -> usize {
@@ -643,7 +646,13 @@ impl Handler {
643
646
_ => format ! ( "aborting due to {} previous errors" , self . err_count( ) )
644
647
} ;
645
648
646
- let _ = self . fatal ( & s) ;
649
+ let _ = if self . treat_err_as_bug ( ) {
650
+ self . fatal ( & s)
651
+ } else {
652
+ // only emit one backtrace when using `-Z treat-err-as-bug=X`
653
+ DiagnosticBuilder :: new ( self , Fatal , & s) . emit ( ) ;
654
+ FatalError
655
+ } ;
647
656
648
657
let can_show_explain = self . emitter . borrow ( ) . should_show_explain ( ) ;
649
658
let are_there_diagnostics = !self . emitted_diagnostic_codes . borrow ( ) . is_empty ( ) ;
0 commit comments