Skip to content

Commit 267d5d3

Browse files
Michael Wrightflip1995
Michael Wright
authored andcommitted
Fix lint_without_lint_pass
1 parent 3971c42 commit 267d5d3

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use toml;
4848

4949
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
5050
// as said in the README.md of this repository. If this changes, please update README.md.
51+
#[macro_export]
5152
macro_rules! declare_clippy_lint {
5253
{ pub $name:tt, style, $description:tt } => {
5354
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }

clippy_lints/src/utils/internal_lints.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010

1111
use crate::utils::{
12-
match_qpath, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
12+
match_def_path, match_qpath, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
1313
};
1414
use if_chain::if_chain;
1515
use crate::rustc::hir;
1616
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
1717
use crate::rustc::hir::*;
18+
use crate::rustc::hir::def::Def;
1819
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
1920
use crate::rustc::{declare_tool_lint, lint_array};
2021
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -161,7 +162,8 @@ impl LintPass for LintWithoutLintPass {
161162
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
162163
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
163164
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
164-
if is_lint_ref_type(ty) {
165+
166+
if is_lint_ref_type(cx, ty) {
165167
self.declared_lints.insert(item.name, item.span);
166168
} else if is_lint_array_type(ty) && item.name == "ARRAY" {
167169
if let VisibilityKind::Inherited = item.vis.node {
@@ -203,19 +205,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
203205
}
204206
}
205207

206-
fn is_lint_ref_type(ty: &Ty) -> bool {
208+
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
207209
if let TyKind::Rptr(
208210
_,
209211
MutTy {
210212
ty: ref inner,
211213
mutbl: MutImmutable,
212214
},
213-
) = ty.node
214-
{
215+
) = ty.node {
215216
if let TyKind::Path(ref path) = inner.node {
216-
return match_qpath(path, &paths::LINT);
217+
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
218+
return match_def_path(cx.tcx, def_id, &paths::LINT);
219+
}
217220
}
218221
}
222+
219223
false
220224
}
221225

tests/ui/lint_without_lint_pass.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![deny(clippy::internal)]
2+
3+
#![feature(rustc_private)]
4+
5+
#[macro_use]
6+
extern crate rustc;
7+
8+
#[macro_use]
9+
extern crate clippy_lints;
10+
11+
declare_clippy_lint!
12+
{
13+
pub TEST_LINT,
14+
correctness,
15+
""
16+
}
17+
18+
fn main() {
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: the lint `TEST_LINT` is not added to any `LintPass`
2+
--> $DIR/lint_without_lint_pass.rs:11:1
3+
|
4+
11 | / declare_clippy_lint!
5+
12 | | {
6+
13 | | pub TEST_LINT,
7+
14 | | correctness,
8+
15 | | ""
9+
16 | | }
10+
| |_^
11+
|
12+
note: lint level defined here
13+
--> $DIR/lint_without_lint_pass.rs:1:9
14+
|
15+
1 | #![deny(clippy::internal)]
16+
| ^^^^^^^^^^^^^^^^
17+
= note: #[deny(clippy::lint_without_lint_pass)] implied by #[deny(clippy::internal)]
18+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
19+
20+
error: aborting due to previous error
21+

0 commit comments

Comments
 (0)