@@ -42,6 +42,8 @@ use std::cell::{RefCell, Cell};
4242use std:: mem;
4343use std:: rc:: Rc ;
4444use std:: { error, fmt} ;
45+ use std:: sync:: atomic:: AtomicUsize ;
46+ use std:: sync:: atomic:: Ordering :: SeqCst ;
4547
4648mod diagnostic;
4749mod diagnostic_builder;
@@ -236,7 +238,7 @@ pub use diagnostic_builder::DiagnosticBuilder;
236238pub struct Handler {
237239 pub flags : HandlerFlags ,
238240
239- err_count : Cell < usize > ,
241+ err_count : AtomicUsize ,
240242 emitter : RefCell < Box < Emitter > > ,
241243 continue_after_error : Cell < bool > ,
242244 delayed_span_bug : RefCell < Option < Diagnostic > > ,
@@ -295,7 +297,7 @@ impl Handler {
295297 pub fn with_emitter_and_flags ( e : Box < Emitter > , flags : HandlerFlags ) -> Handler {
296298 Handler {
297299 flags,
298- err_count : Cell :: new ( 0 ) ,
300+ err_count : AtomicUsize :: new ( 0 ) ,
299301 emitter : RefCell :: new ( e) ,
300302 continue_after_error : Cell :: new ( true ) ,
301303 delayed_span_bug : RefCell :: new ( None ) ,
@@ -311,7 +313,7 @@ impl Handler {
311313 // NOTE: DO NOT call this function from rustc, as it relies on `err_count` being non-zero
312314 // if an error happened to avoid ICEs. This function should only be called from tools.
313315 pub fn reset_err_count ( & self ) {
314- self . err_count . set ( 0 ) ;
316+ self . err_count . store ( 0 , SeqCst ) ;
315317 }
316318
317319 pub fn struct_dummy < ' a > ( & ' a self ) -> DiagnosticBuilder < ' a > {
@@ -507,19 +509,19 @@ impl Handler {
507509
508510 fn bump_err_count ( & self ) {
509511 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 ) ;
511513 }
512514
513515 pub fn err_count ( & self ) -> usize {
514- self . err_count . get ( )
516+ self . err_count . load ( SeqCst )
515517 }
516518
517519 pub fn has_errors ( & self ) -> bool {
518- self . err_count . get ( ) > 0
520+ self . err_count ( ) > 0
519521 }
520522 pub fn abort_if_errors ( & self ) {
521523 let s;
522- match self . err_count . get ( ) {
524+ match self . err_count ( ) {
523525 0 => {
524526 if let Some ( bug) = self . delayed_span_bug . borrow_mut ( ) . take ( ) {
525527 DiagnosticBuilder :: new_diagnostic ( self , bug) . emit ( ) ;
@@ -528,7 +530,7 @@ impl Handler {
528530 }
529531 1 => s = "aborting due to previous error" . to_string ( ) ,
530532 _ => {
531- s = format ! ( "aborting due to {} previous errors" , self . err_count. get ( ) ) ;
533+ s = format ! ( "aborting due to {} previous errors" , self . err_count( ) ) ;
532534 }
533535 }
534536
0 commit comments