Skip to content

Commit f9274d8

Browse files
committed
Merge interface::run_compiler calls.
`rustc_driver_impl::run_compiler` currently has two `interface::run_compiler` calls: one for the "no input" case, and one for the normal case. This commit merges the former into the latter, which makes the control flow easier to read and avoids some duplication. It also makes it clearer that the "no input" case will describe lints before printing crate info, while the normal case does it in the reverse order. Possibly a bug?
1 parent d5b5dd5 commit f9274d8

File tree

1 file changed

+23
-30
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+23
-30
lines changed

compiler/rustc_driver_impl/src/lib.rs

+23-30
Original file line numberDiff line numberDiff line change
@@ -338,41 +338,14 @@ fn run_compiler(
338338
expanded_args: args,
339339
};
340340

341-
match make_input(&default_handler, &matches.free) {
341+
let has_input = match make_input(&default_handler, &matches.free) {
342342
Err(reported) => return Err(reported),
343343
Ok(Some(input)) => {
344344
config.input = input;
345-
346-
callbacks.config(&mut config);
345+
true // has input: normal compilation
347346
}
348347
Ok(None) => match matches.free.len() {
349-
0 => {
350-
callbacks.config(&mut config);
351-
352-
default_handler.abort_if_errors();
353-
354-
interface::run_compiler(config, |compiler| {
355-
let sopts = &compiler.session().opts;
356-
let handler = EarlyErrorHandler::new(sopts.error_format);
357-
358-
if sopts.describe_lints {
359-
describe_lints(compiler.session());
360-
return;
361-
}
362-
let should_stop = print_crate_info(
363-
&handler,
364-
&**compiler.codegen_backend(),
365-
compiler.session(),
366-
false,
367-
);
368-
369-
if should_stop == Compilation::Stop {
370-
return;
371-
}
372-
handler.early_error("no input filename given")
373-
});
374-
return Ok(());
375-
}
348+
0 => false, // no input: we will exit early
376349
1 => panic!("make_input should have provided valid inputs"),
377350
_ => default_handler.early_error(format!(
378351
"multiple input filenames provided (first two filenames are `{}` and `{}`)",
@@ -381,12 +354,32 @@ fn run_compiler(
381354
},
382355
};
383356

357+
callbacks.config(&mut config);
358+
384359
default_handler.abort_if_errors();
360+
drop(default_handler);
385361

386362
interface::run_compiler(config, |compiler| {
387363
let sess = compiler.session();
388364
let handler = EarlyErrorHandler::new(sess.opts.error_format);
389365

366+
if !has_input {
367+
if sess.opts.describe_lints {
368+
describe_lints(compiler.session());
369+
return sess.compile_status();
370+
}
371+
let should_stop = print_crate_info(
372+
&handler,
373+
&**compiler.codegen_backend(),
374+
compiler.session(),
375+
false,
376+
);
377+
if should_stop == Compilation::Continue {
378+
handler.early_error("no input filename given")
379+
}
380+
return sess.compile_status();
381+
}
382+
390383
let should_stop = print_crate_info(&handler, &**compiler.codegen_backend(), sess, true)
391384
.and_then(|| {
392385
list_metadata(&handler, sess, &*compiler.codegen_backend().metadata_loader())

0 commit comments

Comments
 (0)