Skip to content

Commit 562cc63

Browse files
committed
Fix lint_without_lint_pass lint
1 parent 237e168 commit 562cc63

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

clippy_lints/src/utils/internal_lints.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{
2-
match_def_path, match_type, method_calls, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
2+
is_expn_of, match_def_path, match_type, method_calls, paths, span_help_and_lint, span_lint, span_lint_and_sugg,
3+
walk_ptrs_ty,
34
};
45
use if_chain::if_chain;
56
use rustc::hir;
@@ -148,25 +149,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
148149
if is_lint_ref_type(cx, ty) {
149150
self.declared_lints.insert(item.ident.name, item.span);
150151
}
151-
} else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.kind {
152-
if_chain! {
153-
if let hir::TraitRef{path, ..} = trait_ref;
154-
if let Res::Def(DefKind::Trait, def_id) = path.res;
155-
if match_def_path(cx, def_id, &paths::LINT_PASS);
156-
then {
157-
let mut collector = LintCollector {
158-
output: &mut self.registered_lints,
159-
cx,
160-
};
161-
let body_id = cx.tcx.hir().body_owned_by(
162-
impl_item_refs
163-
.iter()
164-
.find(|iiref| iiref.ident.as_str() == "get_lints")
165-
.expect("LintPass needs to implement get_lints")
166-
.id.hir_id
167-
);
168-
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
169-
}
152+
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
153+
|| is_expn_of(item.span, "declare_lint_pass").is_some()
154+
{
155+
if let hir::ItemKind::Impl(.., None, _, ref impl_item_refs) = item.kind {
156+
let mut collector = LintCollector {
157+
output: &mut self.registered_lints,
158+
cx,
159+
};
160+
let body_id = cx.tcx.hir().body_owned_by(
161+
impl_item_refs
162+
.iter()
163+
.find(|iiref| iiref.ident.as_str() == "get_lints")
164+
.expect("LintPass needs to implement get_lints")
165+
.id
166+
.hir_id,
167+
);
168+
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
170169
}
171170
}
172171
}

clippy_lints/src/utils/paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator
4646
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
4747
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
4848
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];
49-
pub const LINT_PASS: [&str; 3] = ["rustc", "lint", "LintPass"];
5049
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
5150
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
5251
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];

tests/ui/lint_without_lint_pass.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ declare_clippy_lint! {
2020
""
2121
}
2222

23+
declare_clippy_lint! {
24+
pub TEST_LINT_REGISTERED_ONLY_IMPL,
25+
correctness,
26+
""
27+
}
28+
2329
pub struct Pass;
2430
impl LintPass for Pass {
2531
fn name(&self) -> &'static str {
@@ -30,6 +36,6 @@ impl LintPass for Pass {
3036
declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]);
3137

3238
pub struct Pass3;
33-
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED]);
39+
impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED_ONLY_IMPL]);
3440

3541
fn main() {}

0 commit comments

Comments
 (0)