From b74b4b09d118aed77d41387642d4f7b7b6b4c487 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 4 Mar 2024 16:31:49 +1100 Subject: [PATCH] Rename all `ParseSess` variables/fields/lifetimes as `psess`. Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`. --- clippy_lints/src/disallowed_script_idents.rs | 2 +- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- src/driver.rs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index d5205e65cef..0c1bb2da7e8 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -72,7 +72,7 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) { return; } - let symbols = cx.sess().parse_sess.symbol_gallery.symbols.lock(); + let symbols = cx.sess().psess.symbol_gallery.symbols.lock(); // Sort by `Span` so that error messages make sense with respect to the // order of identifier locations in the code. let mut symbols: Vec<_> = symbols.iter().collect(); diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index fdb9ceb7179..e55a988321b 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -48,9 +48,9 @@ fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let sess = ParseSess::with_dcx(dcx, sm); + let psess = ParseSess::with_dcx(dcx, sm); - let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { + let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) { Ok(p) => p, Err(errs) => { errs.into_iter().for_each(Diag::cancel); diff --git a/src/driver.rs b/src/driver.rs index b966fcf9b80..8fc66644632 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -68,8 +68,8 @@ fn test_arg_value() { assert_eq!(arg_value(args, "--foo", |_| true), None); } -fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option) { - parse_sess.env_depinfo.get_mut().insert(( +fn track_clippy_args(psess: &mut ParseSess, args_env_var: &Option) { + psess.env_depinfo.get_mut().insert(( Symbol::intern("CLIPPY_ARGS"), args_env_var.as_deref().map(Symbol::intern), )); @@ -77,8 +77,8 @@ fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option) /// Track files that may be accessed at runtime in `file_depinfo` so that cargo will re-run clippy /// when any of them are modified -fn track_files(parse_sess: &mut ParseSess) { - let file_depinfo = parse_sess.file_depinfo.get_mut(); +fn track_files(psess: &mut ParseSess) { + let file_depinfo = psess.file_depinfo.get_mut(); // Used by `clippy::cargo` lints and to determine the MSRV. `cargo clippy` executes `clippy-driver` // with the current directory set to `CARGO_MANIFEST_DIR` so a relative path is fine @@ -115,8 +115,8 @@ 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.parse_sess_created = Some(Box::new(move |parse_sess| { - track_clippy_args(parse_sess, &clippy_args_var); + config.psess_created = Some(Box::new(move |psess| { + track_clippy_args(psess, &clippy_args_var); })); } } @@ -132,13 +132,13 @@ 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.parse_sess_created = Some(Box::new(move |parse_sess| { - track_clippy_args(parse_sess, &clippy_args_var); - track_files(parse_sess); + config.psess_created = Some(Box::new(move |psess| { + track_clippy_args(psess, &clippy_args_var); + track_files(psess); // Trigger a rebuild if CLIPPY_CONF_DIR changes. The value must be a valid string so // changes between dirs that are invalid UTF-8 will not trigger rebuilds - parse_sess.env_depinfo.get_mut().insert(( + psess.env_depinfo.get_mut().insert(( Symbol::intern("CLIPPY_CONF_DIR"), env::var("CLIPPY_CONF_DIR").ok().map(|dir| Symbol::intern(&dir)), ));