Fix lint_without_lint_pass lint
This commit is contained in:
parent
237e168b89
commit
562cc63b7e
@ -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,25 +149,23 @@ 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 {
|
||||
let mut collector = LintCollector {
|
||||
output: &mut self.registered_lints,
|
||||
cx,
|
||||
};
|
||||
let body_id = cx.tcx.hir().body_owned_by(
|
||||
impl_item_refs
|
||||
.iter()
|
||||
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
||||
.expect("LintPass needs to implement get_lints")
|
||||
.id.hir_id
|
||||
);
|
||||
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
||||
}
|
||||
} 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,
|
||||
};
|
||||
let body_id = cx.tcx.hir().body_owned_by(
|
||||
impl_item_refs
|
||||
.iter()
|
||||
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
||||
.expect("LintPass needs to implement get_lints")
|
||||
.id
|
||||
.hir_id,
|
||||
);
|
||||
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"];
|
||||
|
@ -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() {}
|
||||
|
Loading…
Reference in New Issue
Block a user