Skip to content

Commit 8aee35e

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 706eb16 commit 8aee35e

File tree

1 file changed

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

1 file changed

+18
-30
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 18 additions & 30 deletions
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,13 +354,28 @@ 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 codegen_backend = compiler.codegen_backend();
389365
let handler = EarlyErrorHandler::new(sess.opts.error_format);
390366

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

0 commit comments

Comments
 (0)