@@ -117,6 +117,57 @@ impl DocAccessLevels for AccessLevels<DefId> {
117
117
}
118
118
}
119
119
120
+ /// Creates a new diagnostic `Handler` that can be used to emit warnings and errors.
121
+ ///
122
+ /// If the given `error_format` is `ErrorOutputType::Json` and no `CodeMap` is given, a new one
123
+ /// will be created for the handler.
124
+ pub fn new_handler ( error_format : ErrorOutputType , codemap : Option < Lrc < codemap:: CodeMap > > )
125
+ -> errors:: Handler
126
+ {
127
+ // rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
128
+ // stick to the defaults
129
+ let sessopts = config:: basic_options ( ) ;
130
+ let emitter: Box < dyn Emitter + sync:: Send > = match error_format {
131
+ ErrorOutputType :: HumanReadable ( color_config) => Box :: new (
132
+ EmitterWriter :: stderr (
133
+ color_config,
134
+ codemap. map ( |cm| cm as _ ) ,
135
+ false ,
136
+ sessopts. debugging_opts . teach ,
137
+ ) . ui_testing ( sessopts. debugging_opts . ui_testing )
138
+ ) ,
139
+ ErrorOutputType :: Json ( pretty) => {
140
+ let codemap = codemap. unwrap_or_else (
141
+ || Lrc :: new ( codemap:: CodeMap :: new ( sessopts. file_path_mapping ( ) ) ) ) ;
142
+ Box :: new (
143
+ JsonEmitter :: stderr (
144
+ None ,
145
+ codemap,
146
+ pretty,
147
+ sessopts. debugging_opts . suggestion_applicability ,
148
+ ) . ui_testing ( sessopts. debugging_opts . ui_testing )
149
+ )
150
+ } ,
151
+ ErrorOutputType :: Short ( color_config) => Box :: new (
152
+ EmitterWriter :: stderr (
153
+ color_config,
154
+ codemap. map ( |cm| cm as _ ) ,
155
+ true ,
156
+ false )
157
+ ) ,
158
+ } ;
159
+
160
+ errors:: Handler :: with_emitter_and_flags (
161
+ emitter,
162
+ errors:: HandlerFlags {
163
+ can_emit_warnings : true ,
164
+ treat_err_as_bug : false ,
165
+ external_macro_backtrace : false ,
166
+ ..Default :: default ( )
167
+ } ,
168
+ )
169
+ }
170
+
120
171
pub fn run_core ( search_paths : SearchPaths ,
121
172
cfgs : Vec < String > ,
122
173
externs : config:: Externs ,
@@ -159,41 +210,11 @@ pub fn run_core(search_paths: SearchPaths,
159
210
} ,
160
211
error_format,
161
212
edition,
162
- ..config:: basic_options ( ) . clone ( )
213
+ ..config:: basic_options ( )
163
214
} ;
164
215
driver:: spawn_thread_pool ( sessopts, move |sessopts| {
165
216
let codemap = Lrc :: new ( codemap:: CodeMap :: new ( sessopts. file_path_mapping ( ) ) ) ;
166
- let emitter: Box < dyn Emitter + sync:: Send > = match error_format {
167
- ErrorOutputType :: HumanReadable ( color_config) => Box :: new (
168
- EmitterWriter :: stderr (
169
- color_config,
170
- Some ( codemap. clone ( ) ) ,
171
- false ,
172
- sessopts. debugging_opts . teach ,
173
- ) . ui_testing ( sessopts. debugging_opts . ui_testing )
174
- ) ,
175
- ErrorOutputType :: Json ( pretty) => Box :: new (
176
- JsonEmitter :: stderr (
177
- None ,
178
- codemap. clone ( ) ,
179
- pretty,
180
- sessopts. debugging_opts . suggestion_applicability ,
181
- ) . ui_testing ( sessopts. debugging_opts . ui_testing )
182
- ) ,
183
- ErrorOutputType :: Short ( color_config) => Box :: new (
184
- EmitterWriter :: stderr ( color_config, Some ( codemap. clone ( ) ) , true , false )
185
- ) ,
186
- } ;
187
-
188
- let diagnostic_handler = errors:: Handler :: with_emitter_and_flags (
189
- emitter,
190
- errors:: HandlerFlags {
191
- can_emit_warnings : true ,
192
- treat_err_as_bug : false ,
193
- external_macro_backtrace : false ,
194
- ..Default :: default ( )
195
- } ,
196
- ) ;
217
+ let diagnostic_handler = new_handler ( error_format, Some ( codemap. clone ( ) ) ) ;
197
218
198
219
let mut sess = session:: build_session_ (
199
220
sessopts, cpath, diagnostic_handler, codemap,
0 commit comments