From 3c5e7e8969d4bd705341571215a96964e1a2565e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 23 Apr 2026 14:28:43 +1000 Subject: [PATCH] Simplify `Config::track_state`. This is a callback used to track otherwise untracked state. It was added in #116731 for Clippy. (It was originally named `hash_untracked_state`, and examples in the rustc-dev-guide still use that name.) The `StableHasher` argument is unused, and probably has never been used. There is a FIXME comment pointing this out, which was added more than a year ago. This commit removes the `StableHasher` callback argument. This also removes the need for `Options::untracked_state_hash`. --- compiler/rustc_interface/src/interface.rs | 11 ++--------- compiler/rustc_session/src/config.rs | 2 -- compiler/rustc_session/src/options.rs | 4 ---- .../examples/rustc-interface-example.rs | 4 ++-- .../examples/rustc-interface-getting-diagnostics.rs | 4 ++-- src/tools/clippy/src/driver.rs | 4 ++-- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index fa4d4588caab..a20aa317e06a 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -6,7 +6,6 @@ use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::jobserver::{self, Proxy}; -use rustc_data_structures::stable_hasher::StableHasher; use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed}; use rustc_lint::LintStore; use rustc_middle::ty; @@ -339,11 +338,7 @@ pub struct Config { /// This is a callback to track otherwise untracked state used by the caller. /// /// You can write to `sess.env_depinfo` and `sess.file_depinfo` to track env vars and files. - /// To track any other state you can write to the given hasher. If the hash changes between - /// runs the incremental cache will be cleared. - /// - /// The hashing functionality has no known user. FIXME should this be removed? - pub track_state: Option>, + pub track_state: Option>, /// This is a callback from the driver that is called when we're registering lints; /// it is called during lint loading when we have the LintStore in a non-shared state. @@ -468,9 +463,7 @@ pub fn run_compiler(config: Config, f: impl FnOnce(&Compiler) -> R + Se } if let Some(track_state) = config.track_state { - let mut hasher = StableHasher::new(); - track_state(&sess, &mut hasher); - sess.opts.untracked_state_hash = hasher.finish() + track_state(&sess); } // Even though the session holds the lint store, we can't build the diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 81ccfcc43454..d84bfeb8fff8 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1419,7 +1419,6 @@ fn default() -> Options { target_triple: TargetTuple::from_tuple(host_tuple()), test: false, incremental: None, - untracked_state_hash: Default::default(), unstable_opts, prints: Vec::new(), cg: Default::default(), @@ -2770,7 +2769,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M target_triple, test, incremental, - untracked_state_hash: Default::default(), unstable_opts, prints, cg, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index ef3e061e78a5..2a2d46615e2e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -332,10 +332,6 @@ pub struct Options { /// If `Some`, enable incremental compilation, using the given /// directory to store intermediate results. incremental: Option [UNTRACKED], - /// Set based on the result of the `Config::track_state` callback - /// for custom drivers to invalidate the incremental cache. - #[rustc_lint_opt_deny_field_access("should only be used via `Config::track_state`")] - untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH], unstable_opts: UnstableOptions [SUBSTRUCT] { TARGET_MODIFIER: UnstableOptions(UnstableOptionsTargetModifiers) }, prints: Vec [UNTRACKED], diff --git a/src/doc/rustc-dev-guide/examples/rustc-interface-example.rs b/src/doc/rustc-dev-guide/examples/rustc-interface-example.rs index b4439504650a..4601d9adbb64 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-interface-example.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-interface-example.rs @@ -50,7 +50,7 @@ fn main() { make_codegen_backend: None, expanded_args: Vec::new(), ice_file: None, - hash_untracked_state: None, + track_state: None, using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, }; rustc_interface::run_compiler(config, |compiler| { @@ -72,4 +72,4 @@ fn main() { } }); }); -} \ No newline at end of file +} diff --git a/src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs b/src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs index 342316ba670a..ea2a772703bb 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs @@ -78,7 +78,7 @@ fn main() { make_codegen_backend: None, expanded_args: Vec::new(), ice_file: None, - hash_untracked_state: None, + track_state: None, using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, }; rustc_interface::run_compiler(config, |compiler| { @@ -97,4 +97,4 @@ fn main() { buffer.lock().unwrap().iter().for_each(|diagnostic| { println!("{diagnostic:#?}"); }); -} \ No newline at end of file +} diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 7b7aac09643a..c682f294048b 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -121,7 +121,7 @@ struct RustcCallbacks { impl rustc_driver::Callbacks for RustcCallbacks { fn config(&mut self, config: &mut interface::Config) { let clippy_args_var = self.clippy_args_var.take(); - config.track_state = Some(Box::new(move |sess, _hasher| { + config.track_state = Some(Box::new(move |sess| { track_clippy_args(sess, clippy_args_var.as_deref()); })); config.extra_symbols = sym::EXTRA_SYMBOLS.into(); @@ -138,7 +138,7 @@ fn config(&mut self, config: &mut interface::Config) { let conf_path = clippy_config::lookup_conf_file(); let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); - config.track_state = Some(Box::new(move |sess, _hasher| { + config.track_state = Some(Box::new(move |sess| { track_clippy_args(sess, clippy_args_var.as_deref()); track_files(sess);