Skip to content

Commit 446c8e0

Browse files
committed
Move describe_lints calls.
Currently we have an inconsistency between the "input" and "no input" cases: - no input: `rustc --print=sysroot -Whelp` prints the lint help. - input: `rustc --print=sysroot -Whelp a.rs` prints the sysroot. It makes sense to print the lint help in both cases, because that's what happens with `--help`/`-Zhelp`/`-Chelp`. In fact, the `describe_lints` in the "input" case happens amazingly late, after *parsing*. This is because, with plugins, lints used to be registered much later, when the global context was created. But rust-lang#117649 moved lint registration much earlier, during session construction. So this commit moves the `describe_lints` call to a single spot for both for both the "input" and "no input" cases, as early as possible. This is still not as early as `--help`/`-Zhelp`/`-Chelp`, because `-Whelp` must wait until the session is constructed.
1 parent 8aee35e commit 446c8e0

File tree

1 file changed

+9
-9
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+9
-9
lines changed

compiler/rustc_driver_impl/src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,18 @@ fn run_compiler(
362362
interface::run_compiler(config, |compiler| {
363363
let sess = compiler.session();
364364
let codegen_backend = compiler.codegen_backend();
365+
366+
// This implements `-Whelp`. It should be handled very early, like
367+
// `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
368+
// it must happen after lints are registered, during session creation.
369+
if sess.opts.describe_lints {
370+
describe_lints(sess);
371+
return sess.compile_status();
372+
}
373+
365374
let handler = EarlyErrorHandler::new(sess.opts.error_format);
366375

367376
if !has_input {
368-
if sess.opts.describe_lints {
369-
describe_lints(sess);
370-
return sess.compile_status();
371-
}
372377
let should_stop = print_crate_info(&handler, codegen_backend, sess, false);
373378
if should_stop == Compilation::Continue {
374379
handler.early_error("no input filename given")
@@ -419,11 +424,6 @@ fn run_compiler(
419424
return early_exit();
420425
}
421426

422-
if sess.opts.describe_lints {
423-
describe_lints(sess);
424-
return early_exit();
425-
}
426-
427427
// Make sure name resolution and macro expansion is run.
428428
queries.global_ctxt()?.enter(|tcx| tcx.resolver_for_lowering(()));
429429

0 commit comments

Comments
 (0)