@@ -30,6 +30,7 @@ use rustc_span::{Loc, MultiSpan, Span};
30
30
31
31
use std:: borrow:: Cow ;
32
32
use std:: hash:: { Hash , Hasher } ;
33
+ use std:: num:: NonZeroUsize ;
33
34
use std:: panic;
34
35
use std:: path:: Path ;
35
36
use std:: { error, fmt} ;
@@ -359,7 +360,7 @@ pub struct HandlerFlags {
359
360
pub can_emit_warnings : bool ,
360
361
/// If true, error-level diagnostics are upgraded to bug-level.
361
362
/// (rustc: see `-Z treat-err-as-bug`)
362
- pub treat_err_as_bug : Option < usize > ,
363
+ pub treat_err_as_bug : Option < NonZeroUsize > ,
363
364
/// If true, immediately emit diagnostics that would otherwise be buffered.
364
365
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
365
366
pub dont_buffer_diagnostics : bool ,
@@ -396,7 +397,7 @@ impl Handler {
396
397
pub fn with_tty_emitter (
397
398
color_config : ColorConfig ,
398
399
can_emit_warnings : bool ,
399
- treat_err_as_bug : Option < usize > ,
400
+ treat_err_as_bug : Option < NonZeroUsize > ,
400
401
sm : Option < Lrc < SourceMap > > ,
401
402
) -> Self {
402
403
Self :: with_tty_emitter_and_flags (
@@ -424,7 +425,7 @@ impl Handler {
424
425
425
426
pub fn with_emitter (
426
427
can_emit_warnings : bool ,
427
- treat_err_as_bug : Option < usize > ,
428
+ treat_err_as_bug : Option < NonZeroUsize > ,
428
429
emitter : Box < dyn Emitter + sync:: Send > ,
429
430
) -> Self {
430
431
Handler :: with_emitter_and_flags (
@@ -841,7 +842,7 @@ impl HandlerInner {
841
842
}
842
843
843
844
fn treat_err_as_bug ( & self ) -> bool {
844
- self . flags . treat_err_as_bug . map_or ( false , |c| self . err_count ( ) >= c)
845
+ self . flags . treat_err_as_bug . map_or ( false , |c| self . err_count ( ) >= c. get ( ) )
845
846
}
846
847
847
848
fn print_error_count ( & mut self , registry : & Registry ) {
@@ -950,7 +951,7 @@ impl HandlerInner {
950
951
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
951
952
// incrementing `err_count` by one, so we need to +1 the comparing.
952
953
// FIXME: Would be nice to increment err_count in a more coherent way.
953
- if self . flags . treat_err_as_bug . map_or ( false , |c| self . err_count ( ) + 1 >= c) {
954
+ if self . flags . treat_err_as_bug . map_or ( false , |c| self . err_count ( ) + 1 >= c. get ( ) ) {
954
955
// FIXME: don't abort here if report_delayed_bugs is off
955
956
self . span_bug ( sp, msg) ;
956
957
}
@@ -1023,7 +1024,7 @@ impl HandlerInner {
1023
1024
1024
1025
fn panic_if_treat_err_as_bug ( & self ) {
1025
1026
if self . treat_err_as_bug ( ) {
1026
- match ( self . err_count ( ) , self . flags . treat_err_as_bug . unwrap_or ( 0 ) ) {
1027
+ match ( self . err_count ( ) , self . flags . treat_err_as_bug . map ( |c| c . get ( ) ) . unwrap_or ( 0 ) ) {
1027
1028
( 1 , 1 ) => panic ! ( "aborting due to `-Z treat-err-as-bug=1`" ) ,
1028
1029
( 0 , _) | ( 1 , _) => { }
1029
1030
( count, as_bug) => panic ! (
0 commit comments