@@ -59,7 +59,7 @@ use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
59
59
use rustc_data_structures:: AtomicRef ;
60
60
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
61
61
use rustc_data_structures:: stable_hasher:: { Hash128 , StableHasher } ;
62
- use rustc_data_structures:: sync:: Lock ;
62
+ use rustc_data_structures:: sync:: { DynSend , Lock } ;
63
63
pub use rustc_error_messages:: {
64
64
DiagMessage , FluentBundle , LanguageIdentifier , LazyFallbackBundle , MultiSpan , SpanLabel ,
65
65
SubdiagMessage , fallback_fluent_bundle, fluent_bundle,
@@ -676,57 +676,44 @@ impl DiagCtxt {
676
676
Self { inner : Lock :: new ( DiagCtxtInner :: new ( emitter) ) }
677
677
}
678
678
679
- pub fn make_silent (
680
- & self ,
681
- fallback_bundle : LazyFallbackBundle ,
682
- fatal_note : Option < String > ,
683
- emit_fatal_diagnostic : bool ,
684
- ) {
685
- self . wrap_emitter ( |old_dcx| {
686
- Box :: new ( emitter:: SilentEmitter {
687
- fallback_bundle,
688
- fatal_dcx : DiagCtxt { inner : Lock :: new ( old_dcx) } ,
689
- fatal_note,
690
- emit_fatal_diagnostic,
691
- } )
692
- } ) ;
693
- }
694
-
695
- fn wrap_emitter < F > ( & self , f : F )
696
- where
697
- F : FnOnce ( DiagCtxtInner ) -> Box < DynEmitter > ,
698
- {
699
- // A empty type that implements `Emitter` so that a `DiagCtxtInner` can be constructed
700
- // to temporarily swap in place of the real one, which will be used in constructing
701
- // its replacement.
679
+ pub fn make_silent ( & self , fatal_note : Option < String > , emit_fatal_diagnostic : bool ) {
680
+ // An empty type that implements `Emitter` to temporarily swap in place of the real one,
681
+ // which will be used in constructing its replacement.
702
682
struct FalseEmitter ;
703
683
704
684
impl Emitter for FalseEmitter {
705
685
fn emit_diagnostic ( & mut self , _: DiagInner , _: & Registry ) {
706
- unimplemented ! ( "false emitter must only used during `wrap_emitter `" )
686
+ unimplemented ! ( "false emitter must only used during `make_silent `" )
707
687
}
708
688
709
689
fn source_map ( & self ) -> Option < & SourceMap > {
710
- unimplemented ! ( "false emitter must only used during `wrap_emitter `" )
690
+ unimplemented ! ( "false emitter must only used during `make_silent `" )
711
691
}
712
692
}
713
693
714
694
impl translation:: Translate for FalseEmitter {
715
695
fn fluent_bundle ( & self ) -> Option < & FluentBundle > {
716
- unimplemented ! ( "false emitter must only used during `wrap_emitter `" )
696
+ unimplemented ! ( "false emitter must only used during `make_silent `" )
717
697
}
718
698
719
699
fn fallback_fluent_bundle ( & self ) -> & FluentBundle {
720
- unimplemented ! ( "false emitter must only used during `wrap_emitter `" )
700
+ unimplemented ! ( "false emitter must only used during `make_silent `" )
721
701
}
722
702
}
723
703
724
704
let mut inner = self . inner . borrow_mut ( ) ;
725
- let mut prev_dcx = DiagCtxtInner :: new ( Box :: new ( FalseEmitter ) ) ;
726
- std:: mem:: swap ( & mut * inner, & mut prev_dcx) ;
727
- let new_emitter = f ( prev_dcx) ;
728
- let mut new_dcx = DiagCtxtInner :: new ( new_emitter) ;
729
- std:: mem:: swap ( & mut * inner, & mut new_dcx) ;
705
+ let mut prev_emitter = Box :: new ( FalseEmitter ) as Box < dyn Emitter + DynSend > ;
706
+ std:: mem:: swap ( & mut inner. emitter , & mut prev_emitter) ;
707
+ let new_emitter = Box :: new ( emitter:: SilentEmitter {
708
+ fatal_emitter : prev_emitter,
709
+ fatal_note,
710
+ emit_fatal_diagnostic,
711
+ } ) ;
712
+ inner. emitter = new_emitter;
713
+ }
714
+
715
+ pub fn set_emitter ( & self , emitter : Box < dyn Emitter + DynSend > ) {
716
+ self . inner . borrow_mut ( ) . emitter = emitter;
730
717
}
731
718
732
719
/// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`.
0 commit comments