@@ -307,7 +307,12 @@ pub use diagnostic_builder::DiagnosticBuilder;
307
307
pub struct Handler {
308
308
pub flags : HandlerFlags ,
309
309
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.
310
314
err_count : AtomicUsize ,
315
+ deduplicated_err_count : AtomicUsize ,
311
316
emitter : Lock < Box < dyn Emitter + sync:: Send > > ,
312
317
continue_after_error : AtomicBool ,
313
318
delayed_span_bugs : Lock < Vec < Diagnostic > > ,
@@ -407,6 +412,7 @@ impl Handler {
407
412
Handler {
408
413
flags,
409
414
err_count : AtomicUsize :: new ( 0 ) ,
415
+ deduplicated_err_count : AtomicUsize :: new ( 0 ) ,
410
416
emitter : Lock :: new ( e) ,
411
417
continue_after_error : AtomicBool :: new ( true ) ,
412
418
delayed_span_bugs : Lock :: new ( Vec :: new ( ) ) ,
@@ -428,6 +434,7 @@ impl Handler {
428
434
pub fn reset_err_count ( & self ) {
429
435
// actually frees the underlying memory (which `clear` would not do)
430
436
* self . emitted_diagnostics . borrow_mut ( ) = Default :: default ( ) ;
437
+ self . deduplicated_err_count . store ( 0 , SeqCst ) ;
431
438
self . err_count . store ( 0 , SeqCst ) ;
432
439
}
433
440
@@ -660,10 +667,10 @@ impl Handler {
660
667
}
661
668
662
669
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 ) {
664
671
0 => return ,
665
672
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 )
667
674
} ;
668
675
if self . treat_err_as_bug ( ) {
669
676
return ;
@@ -769,9 +776,12 @@ impl Handler {
769
776
if self . emitted_diagnostics . borrow_mut ( ) . insert ( diagnostic_hash) {
770
777
self . emitter . borrow_mut ( ) . emit_diagnostic ( db) ;
771
778
if db. is_error ( ) {
772
- self . bump_err_count ( ) ;
779
+ self . deduplicated_err_count . fetch_add ( 1 , SeqCst ) ;
773
780
}
774
781
}
782
+ if db. is_error ( ) {
783
+ self . bump_err_count ( ) ;
784
+ }
775
785
}
776
786
777
787
pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
0 commit comments