Fix lint_without_lint_pass lint

This commit is contained in:
flip1995 2019-10-24 13:54:18 +02:00
parent 237e168b89
commit 562cc63b7e
No known key found for this signature in database
GPG key ID: 693086869D506637
3 changed files with 26 additions and 22 deletions

View file

@ -1,5 +1,6 @@
use crate::utils::{
match_def_path, match_type, method_calls, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
is_expn_of, match_def_path, match_type, method_calls, paths, span_help_and_lint, span_lint, span_lint_and_sugg,
walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc::hir;
@ -148,12 +149,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
if is_lint_ref_type(cx, ty) {
self.declared_lints.insert(item.ident.name, item.span);
}
} else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.kind {
if_chain! {
if let hir::TraitRef{path, ..} = trait_ref;
if let Res::Def(DefKind::Trait, def_id) = path.res;
if match_def_path(cx, def_id, &paths::LINT_PASS);
then {
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
|| is_expn_of(item.span, "declare_lint_pass").is_some()
{
if let hir::ItemKind::Impl(.., None, _, ref impl_item_refs) = item.kind {
let mut collector = LintCollector {
output: &mut self.registered_lints,
cx,
@ -163,13 +162,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
.iter()
.find(|iiref| iiref.ident.as_str() == "get_lints")
.expect("LintPass needs to implement get_lints")
.id.hir_id
.id
.hir_id,
);
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
}
}
}
}
fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate) {
for (lint_name, &lint_span) in &self.declared_lints {

View file

@ -46,7 +46,6 @@ pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];
pub const LINT_PASS: [&str; 3] = ["rustc", "lint", "LintPass"];
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];

View file

@ -20,6 +20,12 @@ declare_clippy_lint! {
""
}
declare_clippy_lint! {
pub TEST_LINT_REGISTERED_ONLY_IMPL,
correctness,
""
}
pub struct Pass;
impl LintPass for Pass {
fn name(&self) -> &'static str {
@ -30,6 +36,6 @@ impl LintPass for Pass {
declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]);
pub struct Pass3;
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED]);
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED_ONLY_IMPL]);
fn main() {}