1
- use std:: borrow:: Cow ;
2
1
use std:: path:: Path ;
3
2
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4
3
5
4
use 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 } ;
7
6
use rustc_errors:: translation:: Translate ;
8
7
use rustc_errors:: { ColorConfig , Diag , DiagCtxt , DiagInner , Level as DiagnosticLevel } ;
9
8
use rustc_session:: parse:: ParseSess as RawParseSess ;
@@ -28,41 +27,6 @@ pub(crate) struct ParseSess {
28
27
can_reset_errors : Lrc < AtomicBool > ,
29
28
}
30
29
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
-
66
30
/// Emit errors against every files expect ones specified in the `ignore_path_set`.
67
31
struct SilentOnIgnoredFilesEmitter {
68
32
ignore_path_set : IntoDynSyncSend < Lrc < IgnorePathSet > > ,
@@ -143,17 +107,23 @@ fn default_dcx(
143
107
ColorConfig :: Never
144
108
} ;
145
109
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
+ } )
148
125
} 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
157
127
} ;
158
128
DiagCtxt :: new ( Box :: new ( SilentOnIgnoredFilesEmitter {
159
129
has_non_ignorable_parser_errors : false ,
@@ -232,7 +202,14 @@ impl ParseSess {
232
202
}
233
203
234
204
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 ) ;
236
213
}
237
214
238
215
pub ( crate ) fn span_to_filename ( & self , span : Span ) -> FileName {
0 commit comments