@@ -33,12 +33,12 @@ use self::Level::*;
33
33
34
34
use emitter:: { Emitter , EmitterWriter } ;
35
35
36
- use rustc_data_structures:: sync:: { self , Lrc } ;
36
+ use rustc_data_structures:: sync:: { self , Lrc , Lock , LockCell } ;
37
37
use rustc_data_structures:: fx:: FxHashSet ;
38
38
use rustc_data_structures:: stable_hasher:: StableHasher ;
39
39
40
40
use std:: borrow:: Cow ;
41
- use std:: cell:: { RefCell , Cell } ;
41
+ use std:: cell:: Cell ;
42
42
use std:: { error, fmt} ;
43
43
use std:: sync:: atomic:: AtomicUsize ;
44
44
use std:: sync:: atomic:: Ordering :: SeqCst ;
@@ -262,19 +262,22 @@ pub struct Handler {
262
262
pub flags : HandlerFlags ,
263
263
264
264
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 > > ,
268
268
269
269
// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
270
270
// emitting the same diagnostic with extended help (`--teach`) twice, which
271
271
// 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 > > ,
273
276
274
277
// This set contains a hash of every diagnostic that has been emitted by
275
278
// this handler. These hashes is used to avoid emitting the same error
276
279
// twice.
277
- emitted_diagnostics : RefCell < FxHashSet < u128 > > ,
280
+ emitted_diagnostics : Lock < FxHashSet < u128 > > ,
278
281
}
279
282
280
283
fn default_track_diagnostic ( _: & Diagnostic ) { }
@@ -315,7 +318,7 @@ impl Handler {
315
318
316
319
pub fn with_emitter ( can_emit_warnings : bool ,
317
320
treat_err_as_bug : bool ,
318
- e : Box < Emitter > )
321
+ e : Box < Emitter + sync :: Send > )
319
322
-> Handler {
320
323
Handler :: with_emitter_and_flags (
321
324
e,
@@ -326,15 +329,16 @@ impl Handler {
326
329
} )
327
330
}
328
331
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 {
330
333
Handler {
331
334
flags,
332
335
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 ( ) ) ,
338
342
}
339
343
}
340
344
@@ -348,7 +352,7 @@ impl Handler {
348
352
/// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
349
353
/// the overall count of emitted error diagnostics.
350
354
pub fn reset_err_count ( & self ) {
351
- self . emitted_diagnostics . replace ( FxHashSet ( ) ) ;
355
+ * self . emitted_diagnostics . borrow_mut ( ) = FxHashSet ( ) ;
352
356
self . err_count . store ( 0 , SeqCst ) ;
353
357
}
354
358
@@ -568,10 +572,10 @@ impl Handler {
568
572
let _ = self . fatal ( & s) ;
569
573
570
574
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 ( ) ;
572
576
if can_show_explain && are_there_diagnostics {
573
577
let mut error_codes =
574
- self . tracked_diagnostic_codes . borrow ( )
578
+ self . emitted_diagnostic_codes . borrow ( )
575
579
. clone ( )
576
580
. into_iter ( )
577
581
. filter_map ( |x| match x {
@@ -630,12 +634,13 @@ impl Handler {
630
634
}
631
635
}
632
636
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.
634
639
///
635
640
/// Used to suppress emitting the same error multiple times with extended explanation when
636
641
/// 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 ( ) )
639
644
}
640
645
641
646
pub fn force_print_db ( & self , mut db : DiagnosticBuilder ) {
@@ -651,7 +656,7 @@ impl Handler {
651
656
} ) ;
652
657
653
658
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 ( ) ) ;
655
660
}
656
661
657
662
let diagnostic_hash = {
0 commit comments