@@ -42,6 +42,8 @@ use std::cell::{RefCell, Cell};
42
42
use std:: mem;
43
43
use std:: rc:: Rc ;
44
44
use std:: { error, fmt} ;
45
+ use std:: sync:: atomic:: AtomicUsize ;
46
+ use std:: sync:: atomic:: Ordering :: SeqCst ;
45
47
46
48
mod diagnostic;
47
49
mod diagnostic_builder;
@@ -236,7 +238,7 @@ pub use diagnostic_builder::DiagnosticBuilder;
236
238
pub struct Handler {
237
239
pub flags : HandlerFlags ,
238
240
239
- err_count : Cell < usize > ,
241
+ err_count : AtomicUsize ,
240
242
emitter : RefCell < Box < Emitter > > ,
241
243
continue_after_error : Cell < bool > ,
242
244
delayed_span_bug : RefCell < Option < Diagnostic > > ,
@@ -295,7 +297,7 @@ impl Handler {
295
297
pub fn with_emitter_and_flags ( e : Box < Emitter > , flags : HandlerFlags ) -> Handler {
296
298
Handler {
297
299
flags,
298
- err_count : Cell :: new ( 0 ) ,
300
+ err_count : AtomicUsize :: new ( 0 ) ,
299
301
emitter : RefCell :: new ( e) ,
300
302
continue_after_error : Cell :: new ( true ) ,
301
303
delayed_span_bug : RefCell :: new ( None ) ,
@@ -311,7 +313,7 @@ impl Handler {
311
313
// NOTE: DO NOT call this function from rustc, as it relies on `err_count` being non-zero
312
314
// if an error happened to avoid ICEs. This function should only be called from tools.
313
315
pub fn reset_err_count ( & self ) {
314
- self . err_count . set ( 0 ) ;
316
+ self . err_count . store ( 0 , SeqCst ) ;
315
317
}
316
318
317
319
pub fn struct_dummy < ' a > ( & ' a self ) -> DiagnosticBuilder < ' a > {
@@ -507,19 +509,19 @@ impl Handler {
507
509
508
510
fn bump_err_count ( & self ) {
509
511
self . panic_if_treat_err_as_bug ( ) ;
510
- self . err_count . set ( self . err_count . get ( ) + 1 ) ;
512
+ self . err_count . fetch_add ( 1 , SeqCst ) ;
511
513
}
512
514
513
515
pub fn err_count ( & self ) -> usize {
514
- self . err_count . get ( )
516
+ self . err_count . load ( SeqCst )
515
517
}
516
518
517
519
pub fn has_errors ( & self ) -> bool {
518
- self . err_count . get ( ) > 0
520
+ self . err_count ( ) > 0
519
521
}
520
522
pub fn abort_if_errors ( & self ) {
521
523
let s;
522
- match self . err_count . get ( ) {
524
+ match self . err_count ( ) {
523
525
0 => {
524
526
if let Some ( bug) = self . delayed_span_bug . borrow_mut ( ) . take ( ) {
525
527
DiagnosticBuilder :: new_diagnostic ( self , bug) . emit ( ) ;
@@ -528,7 +530,7 @@ impl Handler {
528
530
}
529
531
1 => s = "aborting due to previous error" . to_string ( ) ,
530
532
_ => {
531
- s = format ! ( "aborting due to {} previous errors" , self . err_count. get ( ) ) ;
533
+ s = format ! ( "aborting due to {} previous errors" , self . err_count( ) ) ;
532
534
}
533
535
}
534
536
0 commit comments