@@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr
35
35
use rustc_session:: getopts;
36
36
use rustc_session:: lint:: { Lint , LintId } ;
37
37
use rustc_session:: { config, DiagnosticOutput , Session } ;
38
- use rustc_session:: { early_error, early_warn} ;
38
+ use rustc_session:: { early_error, early_error_no_abort , early_warn} ;
39
39
use rustc_span:: source_map:: { FileLoader , FileName } ;
40
40
use rustc_span:: symbol:: sym;
41
41
@@ -199,46 +199,49 @@ fn run_compiler(
199
199
} ;
200
200
201
201
let sopts = config:: build_session_options ( & matches) ;
202
- let cfg = interface:: parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ;
203
-
204
- // We wrap `make_codegen_backend` in another `Option` such that `dummy_config` can take
205
- // ownership of it when necessary, while also allowing the non-dummy config to take ownership
206
- // when `dummy_config` is not used.
207
- let mut make_codegen_backend = Some ( make_codegen_backend) ;
208
-
209
- let mut dummy_config = |sopts, cfg, diagnostic_output| {
210
- let mut config = interface:: Config {
211
- opts : sopts,
212
- crate_cfg : cfg,
213
- input : Input :: File ( PathBuf :: new ( ) ) ,
214
- input_path : None ,
215
- output_file : None ,
216
- output_dir : None ,
217
- file_loader : None ,
218
- diagnostic_output,
219
- stderr : None ,
220
- lint_caps : Default :: default ( ) ,
221
- parse_sess_created : None ,
222
- register_lints : None ,
223
- override_queries : None ,
224
- make_codegen_backend : make_codegen_backend. take ( ) . unwrap ( ) ,
225
- registry : diagnostics_registry ( ) ,
226
- } ;
227
- callbacks. config ( & mut config) ;
228
- config
229
- } ;
230
202
231
203
if let Some ( ref code) = matches. opt_str ( "explain" ) {
232
204
handle_explain ( diagnostics_registry ( ) , code, sopts. error_format ) ;
233
205
return Ok ( ( ) ) ;
234
206
}
235
207
208
+ let cfg = interface:: parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ;
236
209
let ( odir, ofile) = make_output ( & matches) ;
237
- let ( input, input_file_path, input_err) = match make_input ( & matches. free ) {
238
- Some ( v) => v,
210
+ let mut config = interface:: Config {
211
+ opts : sopts,
212
+ crate_cfg : cfg,
213
+ input : Input :: File ( PathBuf :: new ( ) ) ,
214
+ input_path : None ,
215
+ output_file : ofile,
216
+ output_dir : odir,
217
+ file_loader,
218
+ diagnostic_output,
219
+ stderr : None ,
220
+ lint_caps : Default :: default ( ) ,
221
+ parse_sess_created : None ,
222
+ register_lints : None ,
223
+ override_queries : None ,
224
+ make_codegen_backend,
225
+ registry : diagnostics_registry ( ) ,
226
+ } ;
227
+
228
+ match make_input ( & matches. free ) {
229
+ Some ( ( input, input_file_path, input_err) ) => {
230
+ if let Some ( err) = input_err {
231
+ // Immediately stop compilation if there was an issue reading
232
+ // the input (for example if the input stream is not UTF-8).
233
+ early_error_no_abort ( config. opts . error_format , & err. to_string ( ) ) ;
234
+ return Err ( ErrorReported ) ;
235
+ }
236
+
237
+ config. input = input;
238
+ config. input_path = input_file_path;
239
+
240
+ callbacks. config ( & mut config) ;
241
+ }
239
242
None => match matches. free . len ( ) {
240
243
0 => {
241
- let config = dummy_config ( sopts , cfg , diagnostic_output ) ;
244
+ callbacks . config ( & mut config ) ;
242
245
interface:: run_compiler ( config, |compiler| {
243
246
let sopts = & compiler. session ( ) . opts ;
244
247
if sopts. describe_lints {
@@ -260,8 +263,8 @@ fn run_compiler(
260
263
& * * * compiler. codegen_backend ( ) ,
261
264
compiler. session ( ) ,
262
265
None ,
263
- & odir ,
264
- & ofile ,
266
+ & compiler . output_dir ( ) ,
267
+ & compiler . output_file ( ) ,
265
268
) ;
266
269
267
270
if should_stop == Compilation :: Stop {
@@ -273,7 +276,7 @@ fn run_compiler(
273
276
}
274
277
1 => panic ! ( "make_input should have provided valid inputs" ) ,
275
278
_ => early_error (
276
- sopts . error_format ,
279
+ config . opts . error_format ,
277
280
& format ! (
278
281
"multiple input filenames provided (first two filenames are `{}` and `{}`)" ,
279
282
matches. free[ 0 ] , matches. free[ 1 ] ,
@@ -282,35 +285,6 @@ fn run_compiler(
282
285
} ,
283
286
} ;
284
287
285
- if let Some ( err) = input_err {
286
- // Immediately stop compilation if there was an issue reading
287
- // the input (for example if the input stream is not UTF-8).
288
- interface:: run_compiler ( dummy_config ( sopts, cfg, diagnostic_output) , |compiler| {
289
- compiler. session ( ) . err ( & err. to_string ( ) ) ;
290
- } ) ;
291
- return Err ( ErrorReported ) ;
292
- }
293
-
294
- let mut config = interface:: Config {
295
- opts : sopts,
296
- crate_cfg : cfg,
297
- input,
298
- input_path : input_file_path,
299
- output_file : ofile,
300
- output_dir : odir,
301
- file_loader,
302
- diagnostic_output,
303
- stderr : None ,
304
- lint_caps : Default :: default ( ) ,
305
- parse_sess_created : None ,
306
- register_lints : None ,
307
- override_queries : None ,
308
- make_codegen_backend : make_codegen_backend. unwrap ( ) ,
309
- registry : diagnostics_registry ( ) ,
310
- } ;
311
-
312
- callbacks. config ( & mut config) ;
313
-
314
288
interface:: run_compiler ( config, |compiler| {
315
289
let sess = compiler. session ( ) ;
316
290
let should_stop = RustcDefaultCalls :: print_crate_info (
0 commit comments