Fix lint_without_lint_pass lint
This commit is contained in:
parent
237e168b89
commit
562cc63b7e
@ -1,5 +1,6 @@
|
|||||||
use crate::utils::{
|
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 if_chain::if_chain;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
@ -148,12 +149,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||||||
if is_lint_ref_type(cx, ty) {
|
if is_lint_ref_type(cx, ty) {
|
||||||
self.declared_lints.insert(item.ident.name, item.span);
|
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 {
|
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
|
||||||
if_chain! {
|
|| is_expn_of(item.span, "declare_lint_pass").is_some()
|
||||||
if let hir::TraitRef{path, ..} = trait_ref;
|
{
|
||||||
if let Res::Def(DefKind::Trait, def_id) = path.res;
|
if let hir::ItemKind::Impl(.., None, _, ref impl_item_refs) = item.kind {
|
||||||
if match_def_path(cx, def_id, &paths::LINT_PASS);
|
|
||||||
then {
|
|
||||||
let mut collector = LintCollector {
|
let mut collector = LintCollector {
|
||||||
output: &mut self.registered_lints,
|
output: &mut self.registered_lints,
|
||||||
cx,
|
cx,
|
||||||
@ -163,13 +162,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
||||||
.expect("LintPass needs to implement 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);
|
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate) {
|
fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate) {
|
||||||
for (lint_name, &lint_span) in &self.declared_lints {
|
for (lint_name, &lint_span) in &self.declared_lints {
|
||||||
|
@ -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 LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
|
||||||
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
|
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
|
||||||
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];
|
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_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
|
||||||
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
|
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
|
||||||
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
|
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;
|
pub struct Pass;
|
||||||
impl LintPass for Pass {
|
impl LintPass for Pass {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
@ -30,6 +36,6 @@ impl LintPass for Pass {
|
|||||||
declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]);
|
declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]);
|
||||||
|
|
||||||
pub struct Pass3;
|
pub struct Pass3;
|
||||||
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED]);
|
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED_ONLY_IMPL]);
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user