@@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
33
44use rustc_data_structures:: sync:: { Lrc , Send } ;
55use rustc_errors:: emitter:: { Emitter , EmitterWriter } ;
6+ use rustc_errors:: translation:: Translate ;
67use rustc_errors:: { ColorConfig , Diagnostic , Handler , Level as DiagnosticLevel } ;
78use rustc_session:: parse:: ParseSess as RawParseSess ;
89use rustc_span:: {
@@ -28,19 +29,24 @@ pub(crate) struct ParseSess {
2829/// Emitter which discards every error.
2930struct SilentEmitter ;
3031
31- impl Emitter for SilentEmitter {
32- fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
33- None
34- }
35- fn emit_diagnostic ( & mut self , _db : & Diagnostic ) { }
32+ impl Translate for SilentEmitter {
3633 fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
3734 None
3835 }
36+
3937 fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
4038 panic ! ( "silent emitter attempted to translate a diagnostic" ) ;
4139 }
4240}
4341
42+ impl Emitter for SilentEmitter {
43+ fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
44+ None
45+ }
46+
47+ fn emit_diagnostic ( & mut self , _db : & Diagnostic ) { }
48+ }
49+
4450fn silent_emitter ( ) -> Box < dyn Emitter + Send > {
4551 Box :: new ( SilentEmitter { } )
4652}
@@ -62,10 +68,21 @@ impl SilentOnIgnoredFilesEmitter {
6268 }
6369}
6470
71+ impl Translate for SilentOnIgnoredFilesEmitter {
72+ fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
73+ self . emitter . fluent_bundle ( )
74+ }
75+
76+ fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
77+ self . emitter . fallback_fluent_bundle ( )
78+ }
79+ }
80+
6581impl Emitter for SilentOnIgnoredFilesEmitter {
6682 fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
6783 None
6884 }
85+
6986 fn emit_diagnostic ( & mut self , db : & Diagnostic ) {
7087 if db. level ( ) == DiagnosticLevel :: Fatal {
7188 return self . handle_non_ignoreable_error ( db) ;
@@ -88,14 +105,6 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
88105 }
89106 self . handle_non_ignoreable_error ( db) ;
90107 }
91-
92- fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
93- self . emitter . fluent_bundle ( )
94- }
95-
96- fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
97- self . emitter . fallback_fluent_bundle ( )
98- }
99108}
100109
101110fn default_handler (
@@ -340,19 +349,24 @@ mod tests {
340349 num_emitted_errors : Lrc < AtomicU32 > ,
341350 }
342351
352+ impl Translate for TestEmitter {
353+ fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
354+ None
355+ }
356+
357+ fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
358+ panic ! ( "test emitter attempted to translate a diagnostic" ) ;
359+ }
360+ }
361+
343362 impl Emitter for TestEmitter {
344363 fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
345364 None
346365 }
366+
347367 fn emit_diagnostic ( & mut self , _db : & Diagnostic ) {
348368 self . num_emitted_errors . fetch_add ( 1 , Ordering :: Release ) ;
349369 }
350- fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
351- None
352- }
353- fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
354- panic ! ( "test emitter attempted to translate a diagnostic" ) ;
355- }
356370 }
357371
358372 fn build_diagnostic ( level : DiagnosticLevel , span : Option < MultiSpan > ) -> Diagnostic {
0 commit comments