Skip to content

Commit

Permalink
Remove registered_lints field from Session
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorn3 committed Dec 13, 2024
1 parent ead78fd commit ab3051b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
8 changes: 5 additions & 3 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ fn run_compiler(

callbacks.config(&mut config);

let registered_lints = config.register_lints.is_some();

interface::run_compiler(config, |compiler| {
let sess = &compiler.sess;
let codegen_backend = &*compiler.codegen_backend;
Expand All @@ -365,7 +367,7 @@ fn run_compiler(
// `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
// it must happen after lints are registered, during session creation.
if sess.opts.describe_lints {
describe_lints(sess);
describe_lints(sess, registered_lints);
return early_exit();
}

Expand Down Expand Up @@ -982,7 +984,7 @@ the command line flag directly.
}

/// Write to stdout lint command options, together with a list of all available lints
pub fn describe_lints(sess: &Session) {
pub fn describe_lints(sess: &Session, registered_lints: bool) {
safe_println!(
"
Available lint options:
Expand Down Expand Up @@ -1086,7 +1088,7 @@ Available lint options:

print_lint_groups(builtin_groups, true);

match (sess.registered_lints, loaded.len(), loaded_groups.len()) {
match (registered_lints, loaded.len(), loaded_groups.len()) {
(false, 0, _) | (false, _, 0) => {
safe_println!("Lint tools like Clippy can load additional lints and lint groups.");
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = config.register_lints.as_deref() {
register_lints(&sess, &mut lint_store);
sess.registered_lints = true;
}
sess.lint_store = Some(Lrc::new(lint_store));

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ pub struct Session {
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
pub lint_store: Option<Lrc<dyn LintStoreMarker>>,

/// Should be set if any lints are registered in `lint_store`.
pub registered_lints: bool,

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,

Expand Down Expand Up @@ -1068,7 +1065,6 @@ pub fn build_session(
prof,
code_stats: Default::default(),
lint_store: None,
registered_lints: false,
driver_lint_caps,
ctfe_backtrace,
miri_unleashed_features: Lock::new(Default::default()),
Expand Down

0 comments on commit ab3051b

Please sign in to comment.