@@ -307,7 +307,12 @@ pub use diagnostic_builder::DiagnosticBuilder;
307307pub struct Handler {
308308 pub flags : HandlerFlags ,
309309
310+ /// The number of errors that have been emitted, including duplicates.
311+ ///
312+ /// This is not necessarily the count that's reported to the user once
313+ /// compilation ends.
310314 err_count : AtomicUsize ,
315+ deduplicated_err_count : AtomicUsize ,
311316 emitter : Lock < Box < dyn Emitter + sync:: Send > > ,
312317 continue_after_error : AtomicBool ,
313318 delayed_span_bugs : Lock < Vec < Diagnostic > > ,
@@ -352,7 +357,7 @@ pub struct HandlerFlags {
352357
353358impl Drop for Handler {
354359 fn drop ( & mut self ) {
355- if self . err_count ( ) == 0 {
360+ if ! self . has_errors ( ) {
356361 let mut bugs = self . delayed_span_bugs . borrow_mut ( ) ;
357362 let has_bugs = !bugs. is_empty ( ) ;
358363 for bug in bugs. drain ( ..) {
@@ -407,6 +412,7 @@ impl Handler {
407412 Handler {
408413 flags,
409414 err_count : AtomicUsize :: new ( 0 ) ,
415+ deduplicated_err_count : AtomicUsize :: new ( 0 ) ,
410416 emitter : Lock :: new ( e) ,
411417 continue_after_error : AtomicBool :: new ( true ) ,
412418 delayed_span_bugs : Lock :: new ( Vec :: new ( ) ) ,
@@ -428,6 +434,7 @@ impl Handler {
428434 pub fn reset_err_count ( & self ) {
429435 // actually frees the underlying memory (which `clear` would not do)
430436 * self . emitted_diagnostics . borrow_mut ( ) = Default :: default ( ) ;
437+ self . deduplicated_err_count . store ( 0 , SeqCst ) ;
431438 self . err_count . store ( 0 , SeqCst ) ;
432439 }
433440
@@ -660,10 +667,10 @@ impl Handler {
660667 }
661668
662669 pub fn print_error_count ( & self , registry : & Registry ) {
663- let s = match self . err_count ( ) {
670+ let s = match self . deduplicated_err_count . load ( SeqCst ) {
664671 0 => return ,
665672 1 => "aborting due to previous error" . to_string ( ) ,
666- _ => format ! ( "aborting due to {} previous errors" , self . err_count ( ) )
673+ count => format ! ( "aborting due to {} previous errors" , count )
667674 } ;
668675 if self . treat_err_as_bug ( ) {
669676 return ;
@@ -705,10 +712,9 @@ impl Handler {
705712 }
706713
707714 pub fn abort_if_errors ( & self ) {
708- if self . err_count ( ) == 0 {
709- return ;
715+ if self . has_errors ( ) {
716+ FatalError . raise ( ) ;
710717 }
711- FatalError . raise ( ) ;
712718 }
713719 pub fn emit ( & self , msp : & MultiSpan , msg : & str , lvl : Level ) {
714720 if lvl == Warning && !self . flags . can_emit_warnings {
@@ -770,9 +776,12 @@ impl Handler {
770776 if self . emitted_diagnostics . borrow_mut ( ) . insert ( diagnostic_hash) {
771777 self . emitter . borrow_mut ( ) . emit_diagnostic ( db) ;
772778 if db. is_error ( ) {
773- self . bump_err_count ( ) ;
779+ self . deduplicated_err_count . fetch_add ( 1 , SeqCst ) ;
774780 }
775781 }
782+ if db. is_error ( ) {
783+ self . bump_err_count ( ) ;
784+ }
776785 }
777786
778787 pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
0 commit comments