Skip to content

Commit

Permalink
Use rustc_interface::interface::Config::parse_sess_created in Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
hyd-dev committed Mar 15, 2021
1 parent a189df1 commit 1d57c3e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate rustc_session;
extern crate rustc_span;

use rustc_interface::interface;
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::symbol::Symbol;
use rustc_tools_util::VersionInfo;

Expand Down Expand Up @@ -63,8 +63,8 @@ fn test_arg_value() {
assert_eq!(arg_value(args, "--foo", |_| true), None);
}

fn track_clippy_args(sess: &Session, args_env_var: &Option<String>) {
sess.parse_sess.env_depinfo.borrow_mut().insert((
fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option<String>) {
parse_sess.env_depinfo.get_mut().insert((
Symbol::intern("CLIPPY_ARGS"),
args_env_var.as_deref().map(Symbol::intern),
));
Expand All @@ -81,14 +81,9 @@ struct RustcCallbacks {

impl rustc_driver::Callbacks for RustcCallbacks {
fn config(&mut self, config: &mut interface::Config) {
let previous = config.register_lints.take();
let clippy_args_var = self.clippy_args_var.take();
config.register_lints = Some(Box::new(move |sess, lint_store| {
if let Some(ref previous) = previous {
(previous)(sess, lint_store);
}

track_clippy_args(sess, &clippy_args_var);
config.parse_sess_created = Some(Box::new(move |parse_sess| {
track_clippy_args(parse_sess, &clippy_args_var);
}));
}
}
Expand All @@ -101,15 +96,16 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
fn config(&mut self, config: &mut interface::Config) {
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);
}));
config.register_lints = Some(Box::new(move |sess, mut lint_store| {
// technically we're ~guaranteed that this is none but might as well call anything that
// is there already. Certainly it can't hurt.
if let Some(previous) = &previous {
(previous)(sess, lint_store);
}

track_clippy_args(sess, &clippy_args_var);

let conf = clippy_lints::read_conf(&[], &sess);
clippy_lints::register_plugins(&mut lint_store, &sess, &conf);
clippy_lints::register_pre_expansion_lints(&mut lint_store);
Expand Down

0 comments on commit 1d57c3e

Please sign in to comment.