Skip to content

Commit 981f625

Browse files
committed
Remove registered_lints field from Session
It only exists to pass some information from one part of the driver to another part. We can directly pass this information to the function that needs it to reduce the amount of mutation of the Session.
1 parent ead78fd commit 981f625

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

compiler/rustc_driver_impl/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ fn run_compiler(
350350

351351
callbacks.config(&mut config);
352352

353+
let registered_lints = config.register_lints.is_some();
354+
353355
interface::run_compiler(config, |compiler| {
354356
let sess = &compiler.sess;
355357
let codegen_backend = &*compiler.codegen_backend;
@@ -365,7 +367,7 @@ fn run_compiler(
365367
// `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
366368
// it must happen after lints are registered, during session creation.
367369
if sess.opts.describe_lints {
368-
describe_lints(sess);
370+
describe_lints(sess, registered_lints);
369371
return early_exit();
370372
}
371373

@@ -982,7 +984,7 @@ the command line flag directly.
982984
}
983985

984986
/// Write to stdout lint command options, together with a list of all available lints
985-
pub fn describe_lints(sess: &Session) {
987+
pub fn describe_lints(sess: &Session, registered_lints: bool) {
986988
safe_println!(
987989
"
988990
Available lint options:
@@ -1086,7 +1088,7 @@ Available lint options:
10861088

10871089
print_lint_groups(builtin_groups, true);
10881090

1089-
match (sess.registered_lints, loaded.len(), loaded_groups.len()) {
1091+
match (registered_lints, loaded.len(), loaded_groups.len()) {
10901092
(false, 0, _) | (false, _, 0) => {
10911093
safe_println!("Lint tools like Clippy can load additional lints and lint groups.");
10921094
}

compiler/rustc_interface/src/interface.rs

-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
479479
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
480480
if let Some(register_lints) = config.register_lints.as_deref() {
481481
register_lints(&sess, &mut lint_store);
482-
sess.registered_lints = true;
483482
}
484483
sess.lint_store = Some(Lrc::new(lint_store));
485484

compiler/rustc_session/src/session.rs

-4
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ pub struct Session {
156156
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
157157
pub lint_store: Option<Lrc<dyn LintStoreMarker>>,
158158

159-
/// Should be set if any lints are registered in `lint_store`.
160-
pub registered_lints: bool,
161-
162159
/// Cap lint level specified by a driver specifically.
163160
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
164161

@@ -1068,7 +1065,6 @@ pub fn build_session(
10681065
prof,
10691066
code_stats: Default::default(),
10701067
lint_store: None,
1071-
registered_lints: false,
10721068
driver_lint_caps,
10731069
ctfe_backtrace,
10741070
miri_unleashed_features: Lock::new(Default::default()),

src/librustdoc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,13 @@ fn main_args(
846846

847847
let config = core::create_config(input, options, &render_options, using_internal_features);
848848

849+
let registered_lints = config.register_lints.is_some();
850+
849851
interface::run_compiler(config, |compiler| {
850852
let sess = &compiler.sess;
851853

852854
if sess.opts.describe_lints {
853-
rustc_driver::describe_lints(sess);
855+
rustc_driver::describe_lints(sess, registered_lints);
854856
return;
855857
}
856858

0 commit comments

Comments
 (0)