Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Update Clippy #1580

Merged
merged 2 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install:
# Required for Racer autoconfiguration
- rustup component add rust-src
- rustup component add rust-analysis
- rustup component add rustc-dev
matrix:
fast_finish: true
include:
Expand Down
22 changes: 17 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true }

cargo = { git = "https://github.com/rust-lang/cargo", rev = "8b0561d68f12eeb1d72e07ceef464ebf6032a1bc" }
cargo_metadata = "0.8"
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "68ff8b19bc6705724d1e77a8dc17ffb8dfbbe26b", optional = true }
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "66df92aeba64547f3e9600635a30df34b12a11d8", optional = true }
env_logger = "0.7"
failure = "0.1.1"
futures = { version = "0.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion rls-rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env_logger = "0.7"
log = "0.4"
failure = "0.1"
rand = "0.7"
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "68ff8b19bc6705724d1e77a8dc17ffb8dfbbe26b", optional = true }
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "66df92aeba64547f3e9600635a30df34b12a11d8", optional = true }
tokio = { version = "0.1", optional = true }
futures = { version = "0.1", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
51 changes: 13 additions & 38 deletions rls-rustc/src/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,18 @@ pub fn adjust_args(args: Vec<String>, preference: ClippyPreference) -> Vec<Strin
}

#[cfg(feature = "clippy")]
pub fn after_parse_callback(compiler: &rustc_interface::interface::Compiler) {
use rustc_driver::plugin::registry::Registry;

let sess = compiler.session();
let mut registry = Registry::new(
sess,
compiler
.parse()
.expect(
"at this compilation stage \
the crate must be parsed",
)
.peek()
.span,
);
registry.args_hidden = Some(Vec::new());

let conf = clippy_lints::read_conf(&registry);
clippy_lints::register_plugins(&mut registry, &conf);

let Registry {
early_lint_passes, late_lint_passes, lint_groups, llvm_passes, attributes, ..
} = registry;
let mut ls = sess.lint_store.borrow_mut();
for pass in early_lint_passes {
ls.register_early_pass(Some(sess), true, false, pass);
}
for pass in late_lint_passes {
ls.register_late_pass(Some(sess), true, false, false, pass);
}

for (name, (to, deprecated_name)) in lint_groups {
ls.register_group(Some(sess), true, name, deprecated_name, to);
}
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
clippy_lints::register_renamed(&mut ls);
pub fn config(config: &mut rustc_interface::interface::Config) {
let previous = config.register_lints.take();
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);
}

sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
sess.plugin_attributes.borrow_mut().extend(attributes);
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, &conf);
clippy_lints::register_renamed(&mut lint_store);
}));
}
8 changes: 2 additions & 6 deletions rls-rustc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ impl Callbacks for ShimCalls {
fn config(&mut self, config: &mut interface::Config) {
config.opts.debugging_opts.continue_parse_after_error = true;
config.opts.debugging_opts.save_analysis = true;
}

#[cfg(feature = "clippy")]
fn after_parsing(&mut self, compiler: &interface::Compiler) -> Compilation {
#[cfg(feature = "clippy")]
match self.clippy_preference {
Some(preference) if preference != clippy::ClippyPreference::Off => {
clippy::after_parse_callback(compiler);
clippy::config(config);
}
_ => {}
}

Compilation::Continue
}

#[cfg(feature = "ipc")]
Expand Down
57 changes: 14 additions & 43 deletions rls/src/build/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,13 @@ impl rustc_driver::Callbacks for RlsRustcCalls {
// still need in the `after_analysis` callback in order to process and
// pass the computed analysis in-memory.
config.opts.debugging_opts.save_analysis = true;
}

fn after_parsing(&mut self, _compiler: &interface::Compiler) -> Compilation {
#[cfg(feature = "clippy")]
{
if self.clippy_preference != ClippyPreference::Off {
clippy_after_parse_callback(_compiler);
clippy_config(config);
}
}

Compilation::Continue
}

fn after_expansion(&mut self, compiler: &interface::Compiler) -> Compilation {
Expand Down Expand Up @@ -325,45 +321,20 @@ impl rustc_driver::Callbacks for RlsRustcCalls {
}

#[cfg(feature = "clippy")]
fn clippy_after_parse_callback(compiler: &interface::Compiler) {
use self::rustc_driver::plugin::registry::Registry;

let sess = compiler.session();
let mut registry = Registry::new(
sess,
compiler
.parse()
.expect(
"at this compilation stage \
the crate must be parsed",
)
.peek()
.span,
);
registry.args_hidden = Some(Vec::new());

let conf = clippy_lints::read_conf(&registry);
clippy_lints::register_plugins(&mut registry, &conf);

let Registry {
early_lint_passes, late_lint_passes, lint_groups, llvm_passes, attributes, ..
} = registry;
let mut ls = sess.lint_store.borrow_mut();
for pass in early_lint_passes {
ls.register_early_pass(Some(sess), true, false, pass);
}
for pass in late_lint_passes {
ls.register_late_pass(Some(sess), true, false, false, pass);
}

for (name, (to, deprecated_name)) in lint_groups {
ls.register_group(Some(sess), true, name, deprecated_name, to);
}
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
clippy_lints::register_renamed(&mut ls);
fn clippy_config(config: &mut interface::Config) {
let previous = config.register_lints.take();
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);
}

sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
sess.plugin_attributes.borrow_mut().extend(attributes);
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, &conf);
clippy_lints::register_renamed(&mut lint_store);
}));
}

fn fetch_input_files(sess: &Session) -> Vec<PathBuf> {
Expand Down