@@ -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 > > ,
@@ -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 ;
@@ -769,9 +776,12 @@ impl Handler {
769776 if self . emitted_diagnostics . borrow_mut ( ) . insert ( diagnostic_hash) {
770777 self . emitter . borrow_mut ( ) . emit_diagnostic ( db) ;
771778 if db. is_error ( ) {
772- self . bump_err_count ( ) ;
779+ self . deduplicated_err_count . fetch_add ( 1 , SeqCst ) ;
773780 }
774781 }
782+ if db. is_error ( ) {
783+ self . bump_err_count ( ) ;
784+ }
775785 }
776786
777787 pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
0 commit comments