@@ -33,12 +33,12 @@ use self::Level::*;
3333
3434use emitter:: { Emitter , EmitterWriter } ;
3535
36- use rustc_data_structures:: sync:: { self , Lrc } ;
36+ use rustc_data_structures:: sync:: { self , Lrc , Lock , LockCell } ;
3737use rustc_data_structures:: fx:: FxHashSet ;
3838use rustc_data_structures:: stable_hasher:: StableHasher ;
3939
4040use std:: borrow:: Cow ;
41- use std:: cell:: { RefCell , Cell } ;
41+ use std:: cell:: Cell ;
4242use std:: { error, fmt} ;
4343use std:: sync:: atomic:: AtomicUsize ;
4444use std:: sync:: atomic:: Ordering :: SeqCst ;
@@ -262,19 +262,22 @@ pub struct Handler {
262262 pub flags : HandlerFlags ,
263263
264264 err_count : AtomicUsize ,
265- emitter : RefCell < Box < Emitter > > ,
266- continue_after_error : Cell < bool > ,
267- delayed_span_bug : RefCell < Option < Diagnostic > > ,
265+ emitter : Lock < Box < Emitter + sync :: Send > > ,
266+ continue_after_error : LockCell < bool > ,
267+ delayed_span_bug : Lock < Option < Diagnostic > > ,
268268
269269 // This set contains the `DiagnosticId` of all emitted diagnostics to avoid
270270 // emitting the same diagnostic with extended help (`--teach`) twice, which
271271 // would be uneccessary repetition.
272- tracked_diagnostic_codes : RefCell < FxHashSet < DiagnosticId > > ,
272+ taught_diagnostics : Lock < FxHashSet < DiagnosticId > > ,
273+
274+ /// Used to suggest rustc --explain <error code>
275+ emitted_diagnostic_codes : Lock < FxHashSet < DiagnosticId > > ,
273276
274277 // This set contains a hash of every diagnostic that has been emitted by
275278 // this handler. These hashes is used to avoid emitting the same error
276279 // twice.
277- emitted_diagnostics : RefCell < FxHashSet < u128 > > ,
280+ emitted_diagnostics : Lock < FxHashSet < u128 > > ,
278281}
279282
280283fn default_track_diagnostic ( _: & Diagnostic ) { }
@@ -315,7 +318,7 @@ impl Handler {
315318
316319 pub fn with_emitter ( can_emit_warnings : bool ,
317320 treat_err_as_bug : bool ,
318- e : Box < Emitter > )
321+ e : Box < Emitter + sync :: Send > )
319322 -> Handler {
320323 Handler :: with_emitter_and_flags (
321324 e,
@@ -326,15 +329,16 @@ impl Handler {
326329 } )
327330 }
328331
329- pub fn with_emitter_and_flags ( e : Box < Emitter > , flags : HandlerFlags ) -> Handler {
332+ pub fn with_emitter_and_flags ( e : Box < Emitter + sync :: Send > , flags : HandlerFlags ) -> Handler {
330333 Handler {
331334 flags,
332335 err_count : AtomicUsize :: new ( 0 ) ,
333- emitter : RefCell :: new ( e) ,
334- continue_after_error : Cell :: new ( true ) ,
335- delayed_span_bug : RefCell :: new ( None ) ,
336- tracked_diagnostic_codes : RefCell :: new ( FxHashSet ( ) ) ,
337- emitted_diagnostics : RefCell :: new ( FxHashSet ( ) ) ,
336+ emitter : Lock :: new ( e) ,
337+ continue_after_error : LockCell :: new ( true ) ,
338+ delayed_span_bug : Lock :: new ( None ) ,
339+ taught_diagnostics : Lock :: new ( FxHashSet ( ) ) ,
340+ emitted_diagnostic_codes : Lock :: new ( FxHashSet ( ) ) ,
341+ emitted_diagnostics : Lock :: new ( FxHashSet ( ) ) ,
338342 }
339343 }
340344
@@ -348,7 +352,7 @@ impl Handler {
348352 /// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
349353 /// the overall count of emitted error diagnostics.
350354 pub fn reset_err_count ( & self ) {
351- self . emitted_diagnostics . replace ( FxHashSet ( ) ) ;
355+ * self . emitted_diagnostics . borrow_mut ( ) = FxHashSet ( ) ;
352356 self . err_count . store ( 0 , SeqCst ) ;
353357 }
354358
@@ -568,10 +572,10 @@ impl Handler {
568572 let _ = self . fatal ( & s) ;
569573
570574 let can_show_explain = self . emitter . borrow ( ) . should_show_explain ( ) ;
571- let are_there_diagnostics = !self . tracked_diagnostic_codes . borrow ( ) . is_empty ( ) ;
575+ let are_there_diagnostics = !self . emitted_diagnostic_codes . borrow ( ) . is_empty ( ) ;
572576 if can_show_explain && are_there_diagnostics {
573577 let mut error_codes =
574- self . tracked_diagnostic_codes . borrow ( )
578+ self . emitted_diagnostic_codes . borrow ( )
575579 . clone ( )
576580 . into_iter ( )
577581 . filter_map ( |x| match x {
@@ -630,12 +634,13 @@ impl Handler {
630634 }
631635 }
632636
633- /// `true` if a diagnostic with this code has already been emitted in this handler.
637+ /// `true` if we haven't taught a diagnostic with this code already.
638+ /// The caller must then teach the user about such a diagnostic.
634639 ///
635640 /// Used to suppress emitting the same error multiple times with extended explanation when
636641 /// calling `-Zteach`.
637- pub fn code_emitted ( & self , code : & DiagnosticId ) -> bool {
638- self . tracked_diagnostic_codes . borrow ( ) . contains ( code)
642+ pub fn must_teach ( & self , code : & DiagnosticId ) -> bool {
643+ self . taught_diagnostics . borrow_mut ( ) . insert ( code. clone ( ) )
639644 }
640645
641646 pub fn force_print_db ( & self , mut db : DiagnosticBuilder ) {
@@ -651,7 +656,7 @@ impl Handler {
651656 } ) ;
652657
653658 if let Some ( ref code) = diagnostic. code {
654- self . tracked_diagnostic_codes . borrow_mut ( ) . insert ( code. clone ( ) ) ;
659+ self . emitted_diagnostic_codes . borrow_mut ( ) . insert ( code. clone ( ) ) ;
655660 }
656661
657662 let diagnostic_hash = {
0 commit comments