Update clippy for latest rustc changes

Specifically, this revises the clippy integration to utilize a new
callback to register its lints, as the prior editing of lint store in
Session is no longer possible.
This commit is contained in:
Mark Rousskov 2019-10-10 21:46:22 -04:00 committed by flip1995
parent 87536f00e3
commit 7e77f3c29f
No known key found for this signature in database
GPG key ID: 693086869D506637
4 changed files with 1149 additions and 854 deletions

File diff suppressed because it is too large Load diff

View file

@ -54,6 +54,7 @@ declare_clippy_lint! {
"functions taking small copyable arguments by reference"
}
#[derive(Copy, Clone)]
pub struct TriviallyCopyPassByRef {
limit: u64,
}
@ -159,7 +160,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
return;
}
}
},
}
FnKind::Method(..) => (),
_ => return,
}

View file

@ -61,51 +61,20 @@ fn test_arg_value() {
struct ClippyCallbacks;
impl rustc_driver::Callbacks for ClippyCallbacks {
fn after_parsing(&mut self, compiler: &interface::Compiler) -> rustc_driver::Compilation {
let sess = compiler.session();
let mut registry = rustc_driver::plugin::registry::Registry::new(
sess,
compiler
.parse()
.expect(
"at this compilation stage \
the crate must be parsed",
)
.peek()
.span,
);
registry.args_hidden = Some(Vec::new());
fn config(&mut self, 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);
}
let conf = clippy_lints::read_conf(&registry);
clippy_lints::register_plugins(&mut registry, &conf);
let rustc_driver::plugin::registry::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);
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
sess.plugin_attributes.borrow_mut().extend(attributes);
// Continue execution
rustc_driver::Compilation::Continue
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);
}));
}
}

View file

@ -11,22 +11,20 @@ use self::rustc_driver::plugin::Registry;
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry<'_>) {
reg.sess.lint_store.with_read_lock(|lint_store| {
for (lint, _, _) in lint_store.get_lint_groups() {
reg.sess
.struct_warn(
"the clippy plugin is being deprecated, please use cargo clippy or rls with the clippy feature",
)
.emit();
if lint == "clippy" {
// cargo clippy run on a crate that also uses the plugin
return;
}
for (lint, _, _) in reg.lint_store.get_lint_groups() {
reg.sess
.struct_warn(
"the clippy plugin is being deprecated, please use cargo clippy or rls with the clippy feature",
)
.emit();
if lint == "clippy" {
// cargo clippy run on a crate that also uses the plugin
return;
}
});
}
let conf = clippy_lints::read_conf(reg);
clippy_lints::register_plugins(reg, &conf);
let conf = clippy_lints::read_conf(reg.args(), &reg.sess);
clippy_lints::register_plugins(&mut reg.lint_store, &reg.sess, &conf);
}
// only exists to let the dogfood integration test works.