@@ -63,7 +63,7 @@ use emitter::{is_case_difference, DynEmitter, Emitter};
63
63
use registry:: Registry ;
64
64
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
65
65
use rustc_data_structures:: stable_hasher:: { Hash128 , StableHasher } ;
66
- use rustc_data_structures:: sync:: Lock ;
66
+ use rustc_data_structures:: sync:: { Lock , Lrc } ;
67
67
use rustc_data_structures:: AtomicRef ;
68
68
use rustc_lint_defs:: LintExpectationId ;
69
69
use rustc_span:: source_map:: SourceMap ;
@@ -606,29 +606,54 @@ impl DiagCtxt {
606
606
}
607
607
608
608
pub fn new ( emitter : Box < DynEmitter > ) -> Self {
609
- Self {
610
- inner : Lock :: new ( DiagCtxtInner {
611
- flags : DiagCtxtFlags { can_emit_warnings : true , ..Default :: default ( ) } ,
612
- err_guars : Vec :: new ( ) ,
613
- lint_err_guars : Vec :: new ( ) ,
614
- delayed_bugs : Vec :: new ( ) ,
615
- deduplicated_err_count : 0 ,
616
- deduplicated_warn_count : 0 ,
617
- emitter,
618
- must_produce_diag : false ,
619
- has_printed : false ,
620
- suppressed_expected_diag : false ,
621
- taught_diagnostics : Default :: default ( ) ,
622
- emitted_diagnostic_codes : Default :: default ( ) ,
623
- emitted_diagnostics : Default :: default ( ) ,
624
- stashed_diagnostics : Default :: default ( ) ,
625
- future_breakage_diagnostics : Vec :: new ( ) ,
626
- check_unstable_expect_diagnostics : false ,
627
- unstable_expect_diagnostics : Vec :: new ( ) ,
628
- fulfilled_expectations : Default :: default ( ) ,
629
- ice_file : None ,
630
- } ) ,
609
+ Self { inner : Lock :: new ( DiagCtxtInner :: new ( emitter) ) }
610
+ }
611
+
612
+ pub fn make_silent ( & mut self , fallback_bundle : LazyFallbackBundle , fatal_note : Option < String > ) {
613
+ self . wrap_emitter ( |old_dcx| {
614
+ Box :: new ( emitter:: SilentEmitter {
615
+ fallback_bundle,
616
+ fatal_dcx : DiagCtxt { inner : Lock :: new ( old_dcx) } ,
617
+ fatal_note,
618
+ } )
619
+ } ) ;
620
+ }
621
+
622
+ fn wrap_emitter < F > ( & mut self , f : F )
623
+ where
624
+ F : FnOnce ( DiagCtxtInner ) -> Box < DynEmitter > ,
625
+ {
626
+ // A empty type that implements `Emitter` so that a `DiagCtxtInner` can be constructed
627
+ // to temporarily swap in place of the real one, which will be used in constructing
628
+ // its replacement.
629
+ struct FalseEmitter ;
630
+
631
+ impl Emitter for FalseEmitter {
632
+ fn emit_diagnostic ( & mut self , _: DiagInner ) {
633
+ unimplemented ! ( "false emitter must only used during `wrap_emitter`" )
634
+ }
635
+
636
+ fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
637
+ unimplemented ! ( "false emitter must only used during `wrap_emitter`" )
638
+ }
631
639
}
640
+
641
+ impl translation:: Translate for FalseEmitter {
642
+ fn fluent_bundle ( & self ) -> Option < & Lrc < FluentBundle > > {
643
+ unimplemented ! ( "false emitter must only used during `wrap_emitter`" )
644
+ }
645
+
646
+ fn fallback_fluent_bundle ( & self ) -> & FluentBundle {
647
+ unimplemented ! ( "false emitter must only used during `wrap_emitter`" )
648
+ }
649
+ }
650
+
651
+ let mut inner = self . inner . borrow_mut ( ) ;
652
+ let mut prev_dcx = DiagCtxtInner :: new ( Box :: new ( FalseEmitter ) ) ;
653
+ std:: mem:: swap ( & mut * inner, & mut prev_dcx) ;
654
+ let new_emitter = f ( prev_dcx) ;
655
+ let mut new_dcx = DiagCtxtInner :: new ( new_emitter) ;
656
+ std:: mem:: swap ( & mut * inner, & mut new_dcx) ;
632
657
}
633
658
634
659
/// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`.
@@ -1345,6 +1370,30 @@ impl DiagCtxt {
1345
1370
// `DiagCtxt::foo()` just borrows `inner` and forwards a call to
1346
1371
// `DiagCtxtInner::foo`.
1347
1372
impl DiagCtxtInner {
1373
+ fn new ( emitter : Box < DynEmitter > ) -> Self {
1374
+ Self {
1375
+ flags : DiagCtxtFlags { can_emit_warnings : true , ..Default :: default ( ) } ,
1376
+ err_guars : Vec :: new ( ) ,
1377
+ lint_err_guars : Vec :: new ( ) ,
1378
+ delayed_bugs : Vec :: new ( ) ,
1379
+ deduplicated_err_count : 0 ,
1380
+ deduplicated_warn_count : 0 ,
1381
+ emitter,
1382
+ must_produce_diag : false ,
1383
+ has_printed : false ,
1384
+ suppressed_expected_diag : false ,
1385
+ taught_diagnostics : Default :: default ( ) ,
1386
+ emitted_diagnostic_codes : Default :: default ( ) ,
1387
+ emitted_diagnostics : Default :: default ( ) ,
1388
+ stashed_diagnostics : Default :: default ( ) ,
1389
+ future_breakage_diagnostics : Vec :: new ( ) ,
1390
+ check_unstable_expect_diagnostics : false ,
1391
+ unstable_expect_diagnostics : Vec :: new ( ) ,
1392
+ fulfilled_expectations : Default :: default ( ) ,
1393
+ ice_file : None ,
1394
+ }
1395
+ }
1396
+
1348
1397
/// Emit all stashed diagnostics.
1349
1398
fn emit_stashed_diagnostics ( & mut self ) -> Option < ErrorGuaranteed > {
1350
1399
let mut guar = None ;
0 commit comments