Skip to content

Commit 4838843

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 f9274d8 commit 4838843

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
@@ -361,13 +361,18 @@ fn run_compiler(
361361

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

366375
if !has_input {
367-
if sess.opts.describe_lints {
368-
describe_lints(compiler.session());
369-
return sess.compile_status();
370-
}
371376
let should_stop = print_crate_info(
372377
&handler,
373378
&**compiler.codegen_backend(),
@@ -425,11 +430,6 @@ fn run_compiler(
425430
return early_exit();
426431
}
427432

428-
if sess.opts.describe_lints {
429-
describe_lints(sess);
430-
return early_exit();
431-
}
432-
433433
// Make sure name resolution and macro expansion is run.
434434
queries.global_ctxt()?.enter(|tcx| tcx.resolver_for_lowering(()));
435435

0 commit comments

Comments
 (0)