1- use std:: borrow:: Cow ;
21use std:: path:: Path ;
32use std:: sync:: atomic:: { AtomicBool , Ordering } ;
43
54use rustc_data_structures:: sync:: { IntoDynSyncSend , Lrc } ;
6- use rustc_errors:: emitter:: { stderr_destination, DynEmitter , Emitter , HumanEmitter } ;
5+ use rustc_errors:: emitter:: { stderr_destination, DynEmitter , Emitter , HumanEmitter , SilentEmitter } ;
76use rustc_errors:: translation:: Translate ;
87use rustc_errors:: { ColorConfig , Diag , DiagCtxt , DiagInner , Level as DiagnosticLevel } ;
98use rustc_session:: parse:: ParseSess as RawParseSess ;
@@ -28,41 +27,6 @@ pub(crate) struct ParseSess {
2827 can_reset_errors : Lrc < AtomicBool > ,
2928}
3029
31- /// Emitter which discards every error.
32- struct SilentEmitter ;
33-
34- impl Translate for SilentEmitter {
35- fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
36- None
37- }
38-
39- fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
40- panic ! ( "silent emitter attempted to translate a diagnostic" ) ;
41- }
42-
43- // Override `translate_message` for the silent emitter because eager translation of
44- // subdiagnostics result in a call to this.
45- fn translate_message < ' a > (
46- & ' a self ,
47- message : & ' a rustc_errors:: DiagMessage ,
48- _: & ' a rustc_errors:: translation:: FluentArgs < ' _ > ,
49- ) -> Result < Cow < ' _ , str > , rustc_errors:: error:: TranslateError < ' _ > > {
50- rustc_errors:: emitter:: silent_translate ( message)
51- }
52- }
53-
54- impl Emitter for SilentEmitter {
55- fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
56- None
57- }
58-
59- fn emit_diagnostic ( & mut self , _diag : DiagInner ) { }
60- }
61-
62- fn silent_emitter ( ) -> Box < DynEmitter > {
63- Box :: new ( SilentEmitter { } )
64- }
65-
6630/// Emit errors against every files expect ones specified in the `ignore_path_set`.
6731struct SilentOnIgnoredFilesEmitter {
6832 ignore_path_set : IntoDynSyncSend < Lrc < IgnorePathSet > > ,
@@ -143,17 +107,23 @@ fn default_dcx(
143107 ColorConfig :: Never
144108 } ;
145109
146- let emitter = if hide_parse_errors {
147- silent_emitter ( )
110+ let fallback_bundle = rustc_errors:: fallback_fluent_bundle (
111+ rustc_driver:: DEFAULT_LOCALE_RESOURCES . to_vec ( ) ,
112+ false ,
113+ ) ;
114+ let emitter = Box :: new (
115+ HumanEmitter :: new ( stderr_destination ( emit_color) , fallback_bundle. clone ( ) )
116+ . sm ( Some ( source_map. clone ( ) ) ) ,
117+ ) ;
118+
119+ let emitter: Box < DynEmitter > = if hide_parse_errors {
120+ Box :: new ( SilentEmitter {
121+ fallback_bundle,
122+ fatal_dcx : DiagCtxt :: new ( emitter) ,
123+ fatal_note : None ,
124+ } )
148125 } else {
149- let fallback_bundle = rustc_errors:: fallback_fluent_bundle (
150- rustc_driver:: DEFAULT_LOCALE_RESOURCES . to_vec ( ) ,
151- false ,
152- ) ;
153- Box :: new (
154- HumanEmitter :: new ( stderr_destination ( emit_color) , fallback_bundle)
155- . sm ( Some ( source_map. clone ( ) ) ) ,
156- )
126+ emitter
157127 } ;
158128 DiagCtxt :: new ( Box :: new ( SilentOnIgnoredFilesEmitter {
159129 has_non_ignorable_parser_errors : false ,
@@ -232,7 +202,14 @@ impl ParseSess {
232202 }
233203
234204 pub ( crate ) fn set_silent_emitter ( & mut self ) {
235- self . raw_psess . dcx = DiagCtxt :: new ( silent_emitter ( ) ) ;
205+ // Ideally this invocation wouldn't be necessary and the fallback bundle in
206+ // `self.parse_sess.dcx` could be used, but the lock in `DiagCtxt` prevents this.
207+ // See `<rustc_errors::SilentEmitter as Translate>::fallback_fluent_bundle`.
208+ let fallback_bundle = rustc_errors:: fallback_fluent_bundle (
209+ rustc_driver:: DEFAULT_LOCALE_RESOURCES . to_vec ( ) ,
210+ false ,
211+ ) ;
212+ self . raw_psess . dcx . make_silent ( fallback_bundle, None ) ;
236213 }
237214
238215 pub ( crate ) fn span_to_filename ( & self , span : Span ) -> FileName {
0 commit comments