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

Commit d267b49

Browse files
authored
Merge pull request #1580 from flip1995/clippyup
Update Clippy
2 parents 5ce104e + 89c2e73 commit d267b49

File tree

7 files changed

+49
-94
lines changed

7 files changed

+49
-94
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ install:
1111
# Required for Racer autoconfiguration
1212
- rustup component add rust-src
1313
- rustup component add rust-analysis
14+
- rustup component add rustc-dev
1415
matrix:
1516
fast_finish: true
1617
include:

Cargo.lock

+17-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true }
3131

3232
cargo = { git = "https://github.com/rust-lang/cargo", rev = "8b0561d68f12eeb1d72e07ceef464ebf6032a1bc" }
3333
cargo_metadata = "0.8"
34-
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "68ff8b19bc6705724d1e77a8dc17ffb8dfbbe26b", optional = true }
34+
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "66df92aeba64547f3e9600635a30df34b12a11d8", optional = true }
3535
env_logger = "0.7"
3636
failure = "0.1.1"
3737
futures = { version = "0.1", optional = true }

rls-rustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env_logger = "0.7"
1313
log = "0.4"
1414
failure = "0.1"
1515
rand = "0.7"
16-
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "68ff8b19bc6705724d1e77a8dc17ffb8dfbbe26b", optional = true }
16+
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "66df92aeba64547f3e9600635a30df34b12a11d8", optional = true }
1717
tokio = { version = "0.1", optional = true }
1818
futures = { version = "0.1", optional = true }
1919
serde = { version = "1", features = ["derive"], optional = true }

rls-rustc/src/clippy.rs

+13-38
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,18 @@ pub fn adjust_args(args: Vec<String>, preference: ClippyPreference) -> Vec<Strin
4848
}
4949

5050
#[cfg(feature = "clippy")]
51-
pub fn after_parse_callback(compiler: &rustc_interface::interface::Compiler) {
52-
use rustc_driver::plugin::registry::Registry;
53-
54-
let sess = compiler.session();
55-
let mut registry = Registry::new(
56-
sess,
57-
compiler
58-
.parse()
59-
.expect(
60-
"at this compilation stage \
61-
the crate must be parsed",
62-
)
63-
.peek()
64-
.span,
65-
);
66-
registry.args_hidden = Some(Vec::new());
67-
68-
let conf = clippy_lints::read_conf(&registry);
69-
clippy_lints::register_plugins(&mut registry, &conf);
70-
71-
let Registry {
72-
early_lint_passes, late_lint_passes, lint_groups, llvm_passes, attributes, ..
73-
} = registry;
74-
let mut ls = sess.lint_store.borrow_mut();
75-
for pass in early_lint_passes {
76-
ls.register_early_pass(Some(sess), true, false, pass);
77-
}
78-
for pass in late_lint_passes {
79-
ls.register_late_pass(Some(sess), true, false, false, pass);
80-
}
81-
82-
for (name, (to, deprecated_name)) in lint_groups {
83-
ls.register_group(Some(sess), true, name, deprecated_name, to);
84-
}
85-
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
86-
clippy_lints::register_renamed(&mut ls);
51+
pub fn config(config: &mut rustc_interface::interface::Config) {
52+
let previous = config.register_lints.take();
53+
config.register_lints = Some(Box::new(move |sess, mut lint_store| {
54+
// technically we're ~guaranteed that this is none but might as well call anything that
55+
// is there already. Certainly it can't hurt.
56+
if let Some(previous) = &previous {
57+
(previous)(sess, lint_store);
58+
}
8759

88-
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
89-
sess.plugin_attributes.borrow_mut().extend(attributes);
60+
let conf = clippy_lints::read_conf(&[], &sess);
61+
clippy_lints::register_plugins(&mut lint_store, &sess, &conf);
62+
clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf);
63+
clippy_lints::register_renamed(&mut lint_store);
64+
}));
9065
}

rls-rustc/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,14 @@ impl Callbacks for ShimCalls {
9090
fn config(&mut self, config: &mut interface::Config) {
9191
config.opts.debugging_opts.continue_parse_after_error = true;
9292
config.opts.debugging_opts.save_analysis = true;
93-
}
9493

95-
#[cfg(feature = "clippy")]
96-
fn after_parsing(&mut self, compiler: &interface::Compiler) -> Compilation {
94+
#[cfg(feature = "clippy")]
9795
match self.clippy_preference {
9896
Some(preference) if preference != clippy::ClippyPreference::Off => {
99-
clippy::after_parse_callback(compiler);
97+
clippy::config(config);
10098
}
10199
_ => {}
102100
}
103-
104-
Compilation::Continue
105101
}
106102

107103
#[cfg(feature = "ipc")]

rls/src/build/rustc.rs

+14-43
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,13 @@ impl rustc_driver::Callbacks for RlsRustcCalls {
236236
// still need in the `after_analysis` callback in order to process and
237237
// pass the computed analysis in-memory.
238238
config.opts.debugging_opts.save_analysis = true;
239-
}
240239

241-
fn after_parsing(&mut self, _compiler: &interface::Compiler) -> Compilation {
242240
#[cfg(feature = "clippy")]
243241
{
244242
if self.clippy_preference != ClippyPreference::Off {
245-
clippy_after_parse_callback(_compiler);
243+
clippy_config(config);
246244
}
247245
}
248-
249-
Compilation::Continue
250246
}
251247

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

327323
#[cfg(feature = "clippy")]
328-
fn clippy_after_parse_callback(compiler: &interface::Compiler) {
329-
use self::rustc_driver::plugin::registry::Registry;
330-
331-
let sess = compiler.session();
332-
let mut registry = Registry::new(
333-
sess,
334-
compiler
335-
.parse()
336-
.expect(
337-
"at this compilation stage \
338-
the crate must be parsed",
339-
)
340-
.peek()
341-
.span,
342-
);
343-
registry.args_hidden = Some(Vec::new());
344-
345-
let conf = clippy_lints::read_conf(&registry);
346-
clippy_lints::register_plugins(&mut registry, &conf);
347-
348-
let Registry {
349-
early_lint_passes, late_lint_passes, lint_groups, llvm_passes, attributes, ..
350-
} = registry;
351-
let mut ls = sess.lint_store.borrow_mut();
352-
for pass in early_lint_passes {
353-
ls.register_early_pass(Some(sess), true, false, pass);
354-
}
355-
for pass in late_lint_passes {
356-
ls.register_late_pass(Some(sess), true, false, false, pass);
357-
}
358-
359-
for (name, (to, deprecated_name)) in lint_groups {
360-
ls.register_group(Some(sess), true, name, deprecated_name, to);
361-
}
362-
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
363-
clippy_lints::register_renamed(&mut ls);
324+
fn clippy_config(config: &mut interface::Config) {
325+
let previous = config.register_lints.take();
326+
config.register_lints = Some(Box::new(move |sess, mut lint_store| {
327+
// technically we're ~guaranteed that this is none but might as well call anything that
328+
// is there already. Certainly it can't hurt.
329+
if let Some(previous) = &previous {
330+
(previous)(sess, lint_store);
331+
}
364332

365-
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
366-
sess.plugin_attributes.borrow_mut().extend(attributes);
333+
let conf = clippy_lints::read_conf(&[], &sess);
334+
clippy_lints::register_plugins(&mut lint_store, &sess, &conf);
335+
clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf);
336+
clippy_lints::register_renamed(&mut lint_store);
337+
}));
367338
}
368339

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

0 commit comments

Comments
 (0)