@@ -30,6 +30,7 @@ use rustc_span::{Loc, MultiSpan, Span};
3030
3131use std:: borrow:: Cow ;
3232use std:: hash:: { Hash , Hasher } ;
33+ use std:: num:: NonZeroUsize ;
3334use std:: panic;
3435use std:: path:: Path ;
3536use std:: { error, fmt} ;
@@ -359,7 +360,7 @@ pub struct HandlerFlags {
359360 pub can_emit_warnings : bool ,
360361 /// If true, error-level diagnostics are upgraded to bug-level.
361362 /// (rustc: see `-Z treat-err-as-bug`)
362- pub treat_err_as_bug : Option < usize > ,
363+ pub treat_err_as_bug : Option < NonZeroUsize > ,
363364 /// If true, immediately emit diagnostics that would otherwise be buffered.
364365 /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
365366 pub dont_buffer_diagnostics : bool ,
@@ -396,7 +397,7 @@ impl Handler {
396397 pub fn with_tty_emitter (
397398 color_config : ColorConfig ,
398399 can_emit_warnings : bool ,
399- treat_err_as_bug : Option < usize > ,
400+ treat_err_as_bug : Option < NonZeroUsize > ,
400401 sm : Option < Lrc < SourceMap > > ,
401402 ) -> Self {
402403 Self :: with_tty_emitter_and_flags (
@@ -424,7 +425,7 @@ impl Handler {
424425
425426 pub fn with_emitter (
426427 can_emit_warnings : bool ,
427- treat_err_as_bug : Option < usize > ,
428+ treat_err_as_bug : Option < NonZeroUsize > ,
428429 emitter : Box < dyn Emitter + sync:: Send > ,
429430 ) -> Self {
430431 Handler :: with_emitter_and_flags (
@@ -841,7 +842,7 @@ impl HandlerInner {
841842 }
842843
843844 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 ( ) )
845846 }
846847
847848 fn print_error_count ( & mut self , registry : & Registry ) {
@@ -950,7 +951,7 @@ impl HandlerInner {
950951 // This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
951952 // incrementing `err_count` by one, so we need to +1 the comparing.
952953 // 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 ( ) ) {
954955 // FIXME: don't abort here if report_delayed_bugs is off
955956 self . span_bug ( sp, msg) ;
956957 }
@@ -1023,7 +1024,7 @@ impl HandlerInner {
10231024
10241025 fn panic_if_treat_err_as_bug ( & self ) {
10251026 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 ) ) {
10271028 ( 1 , 1 ) => panic ! ( "aborting due to `-Z treat-err-as-bug=1`" ) ,
10281029 ( 0 , _) | ( 1 , _) => { }
10291030 ( count, as_bug) => panic ! (
0 commit comments