@@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr
3535use rustc_session:: getopts;
3636use rustc_session:: lint:: { Lint , LintId } ;
3737use 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} ;
3939use rustc_span:: source_map:: { FileLoader , FileName } ;
4040use rustc_span:: symbol:: sym;
4141
@@ -199,46 +199,49 @@ fn run_compiler(
199199 } ;
200200
201201 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- } ;
230202
231203 if let Some ( ref code) = matches. opt_str ( "explain" ) {
232204 handle_explain ( diagnostics_registry ( ) , code, sopts. error_format ) ;
233205 return Ok ( ( ) ) ;
234206 }
235207
208+ let cfg = interface:: parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ;
236209 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+ }
239242 None => match matches. free . len ( ) {
240243 0 => {
241- let config = dummy_config ( sopts , cfg , diagnostic_output ) ;
244+ callbacks . config ( & mut config ) ;
242245 interface:: run_compiler ( config, |compiler| {
243246 let sopts = & compiler. session ( ) . opts ;
244247 if sopts. describe_lints {
@@ -260,8 +263,8 @@ fn run_compiler(
260263 & * * * compiler. codegen_backend ( ) ,
261264 compiler. session ( ) ,
262265 None ,
263- & odir ,
264- & ofile ,
266+ & compiler . output_dir ( ) ,
267+ & compiler . output_file ( ) ,
265268 ) ;
266269
267270 if should_stop == Compilation :: Stop {
@@ -273,7 +276,7 @@ fn run_compiler(
273276 }
274277 1 => panic ! ( "make_input should have provided valid inputs" ) ,
275278 _ => early_error (
276- sopts . error_format ,
279+ config . opts . error_format ,
277280 & format ! (
278281 "multiple input filenames provided (first two filenames are `{}` and `{}`)" ,
279282 matches. free[ 0 ] , matches. free[ 1 ] ,
@@ -282,35 +285,6 @@ fn run_compiler(
282285 } ,
283286 } ;
284287
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-
314288 interface:: run_compiler ( config, |compiler| {
315289 let sess = compiler. session ( ) ;
316290 let should_stop = RustcDefaultCalls :: print_crate_info (
0 commit comments