@@ -59,7 +59,7 @@ use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
5959use rustc_data_structures:: AtomicRef ;
6060use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
6161use rustc_data_structures:: stable_hasher:: { Hash128 , StableHasher } ;
62- use rustc_data_structures:: sync:: Lock ;
62+ use rustc_data_structures:: sync:: { DynSend , Lock } ;
6363pub use rustc_error_messages:: {
6464 DiagMessage , FluentBundle , LanguageIdentifier , LazyFallbackBundle , MultiSpan , SpanLabel ,
6565 SubdiagMessage , fallback_fluent_bundle, fluent_bundle,
@@ -676,57 +676,44 @@ impl DiagCtxt {
676676 Self { inner : Lock :: new ( DiagCtxtInner :: new ( emitter) ) }
677677 }
678678
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.
702682 struct FalseEmitter ;
703683
704684 impl Emitter for FalseEmitter {
705685 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 `" )
707687 }
708688
709689 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 `" )
711691 }
712692 }
713693
714694 impl translation:: Translate for FalseEmitter {
715695 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 `" )
717697 }
718698
719699 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 `" )
721701 }
722702 }
723703
724704 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;
730717 }
731718
732719 /// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`.
0 commit comments