@@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
3
3
4
4
use rustc_data_structures:: sync:: { Lrc , Send } ;
5
5
use rustc_errors:: emitter:: { Emitter , EmitterWriter } ;
6
+ use rustc_errors:: translation:: Translate ;
6
7
use rustc_errors:: { ColorConfig , Diagnostic , Handler , Level as DiagnosticLevel } ;
7
8
use rustc_session:: parse:: ParseSess as RawParseSess ;
8
9
use rustc_span:: {
@@ -28,19 +29,24 @@ pub(crate) struct ParseSess {
28
29
/// Emitter which discards every error.
29
30
struct SilentEmitter ;
30
31
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 {
36
33
fn fluent_bundle ( & self ) -> Option < & Lrc < rustc_errors:: FluentBundle > > {
37
34
None
38
35
}
36
+
39
37
fn fallback_fluent_bundle ( & self ) -> & rustc_errors:: FluentBundle {
40
38
panic ! ( "silent emitter attempted to translate a diagnostic" ) ;
41
39
}
42
40
}
43
41
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
+
44
50
fn silent_emitter ( ) -> Box < dyn Emitter + Send > {
45
51
Box :: new ( SilentEmitter { } )
46
52
}
@@ -62,10 +68,21 @@ impl SilentOnIgnoredFilesEmitter {
62
68
}
63
69
}
64
70
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
+
65
81
impl Emitter for SilentOnIgnoredFilesEmitter {
66
82
fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
67
83
None
68
84
}
85
+
69
86
fn emit_diagnostic ( & mut self , db : & Diagnostic ) {
70
87
if db. level ( ) == DiagnosticLevel :: Fatal {
71
88
return self . handle_non_ignoreable_error ( db) ;
@@ -88,14 +105,6 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
88
105
}
89
106
self . handle_non_ignoreable_error ( db) ;
90
107
}
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
- }
99
108
}
100
109
101
110
fn default_handler (
@@ -340,19 +349,24 @@ mod tests {
340
349
num_emitted_errors : Lrc < AtomicU32 > ,
341
350
}
342
351
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
+
343
362
impl Emitter for TestEmitter {
344
363
fn source_map ( & self ) -> Option < & Lrc < SourceMap > > {
345
364
None
346
365
}
366
+
347
367
fn emit_diagnostic ( & mut self , _db : & Diagnostic ) {
348
368
self . num_emitted_errors . fetch_add ( 1 , Ordering :: Release ) ;
349
369
}
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
- }
356
370
}
357
371
358
372
fn build_diagnostic ( level : DiagnosticLevel , span : Option < MultiSpan > ) -> Diagnostic {
0 commit comments