@@ -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 > > ,
@@ -352,7 +357,7 @@ pub struct HandlerFlags {
352
357
353
358
impl Drop for Handler {
354
359
fn drop ( & mut self ) {
355
- if self . err_count ( ) == 0 {
360
+ if ! self . has_errors ( ) {
356
361
let mut bugs = self . delayed_span_bugs . borrow_mut ( ) ;
357
362
let has_bugs = !bugs. is_empty ( ) ;
358
363
for bug in bugs. drain ( ..) {
@@ -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 ;
@@ -705,10 +712,9 @@ impl Handler {
705
712
}
706
713
707
714
pub fn abort_if_errors ( & self ) {
708
- if self . err_count ( ) == 0 {
709
- return ;
715
+ if self . has_errors ( ) {
716
+ FatalError . raise ( ) ;
710
717
}
711
- FatalError . raise ( ) ;
712
718
}
713
719
pub fn emit ( & self , msp : & MultiSpan , msg : & str , lvl : Level ) {
714
720
if lvl == Warning && !self . flags . can_emit_warnings {
@@ -770,9 +776,12 @@ impl Handler {
770
776
if self . emitted_diagnostics . borrow_mut ( ) . insert ( diagnostic_hash) {
771
777
self . emitter . borrow_mut ( ) . emit_diagnostic ( db) ;
772
778
if db. is_error ( ) {
773
- self . bump_err_count ( ) ;
779
+ self . deduplicated_err_count . fetch_add ( 1 , SeqCst ) ;
774
780
}
775
781
}
782
+ if db. is_error ( ) {
783
+ self . bump_err_count ( ) ;
784
+ }
776
785
}
777
786
778
787
pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
0 commit comments