Skip to content

Commit c8308c9

Browse files
bors[bot]Michael Wrightflip1995
committed
Merge #3378
3378: Fix lint_without_lint_pass r=phansch a=mikerite Co-authored-by: Michael Wright <[email protected]> Co-authored-by: flip1995 <[email protected]>
2 parents b144c7f + 3d84ffb commit c8308c9

File tree

6 files changed

+74
-19
lines changed

6 files changed

+74
-19
lines changed

clippy_lints/src/lib.rs

+1
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/literal_representation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ impl LintPass for LiteralDigitGrouping {
329329
lint_array!(
330330
UNREADABLE_LITERAL,
331331
INCONSISTENT_DIGIT_GROUPING,
332-
LARGE_DIGIT_GROUPS
332+
LARGE_DIGIT_GROUPS,
333+
MISTYPED_LITERAL_SUFFIXES,
333334
)
334335
}
335336
}

clippy_lints/src/utils/internal_lints.rs

+18-17
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_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};
@@ -160,15 +161,21 @@ impl LintPass for LintWithoutLintPass {
160161

161162
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
162163
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
163-
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
164-
if is_lint_ref_type(ty) {
164+
if let hir::ItemKind::Static(ref ty, MutImmutable, _) = item.node {
165+
if is_lint_ref_type(cx, ty) {
165166
self.declared_lints.insert(item.name, item.span);
166-
} else if is_lint_array_type(ty) && item.name == "ARRAY" {
167-
if let VisibilityKind::Inherited = item.vis.node {
167+
}
168+
} else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
169+
if_chain! {
170+
if let hir::TraitRef{path, ..} = trait_ref;
171+
if let Def::Trait(def_id) = path.def;
172+
if match_def_path(cx.tcx, def_id, &paths::LINT_PASS);
173+
then {
168174
let mut collector = LintCollector {
169175
output: &mut self.registered_lints,
170176
cx,
171177
};
178+
let body_id = cx.tcx.hir.body_owned_by(impl_item_refs[0].id.node_id);
172179
collector.visit_expr(&cx.tcx.hir.body(body_id).value);
173180
}
174181
}
@@ -203,28 +210,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
203210
}
204211
}
205212

206-
fn is_lint_ref_type(ty: &Ty) -> bool {
213+
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
207214
if let TyKind::Rptr(
208215
_,
209216
MutTy {
210217
ty: ref inner,
211218
mutbl: MutImmutable,
212219
},
213-
) = ty.node
214-
{
220+
) = ty.node {
215221
if let TyKind::Path(ref path) = inner.node {
216-
return match_qpath(path, &paths::LINT);
222+
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
223+
return match_def_path(cx.tcx, def_id, &paths::LINT);
224+
}
217225
}
218226
}
219-
false
220-
}
221227

222-
fn is_lint_array_type(ty: &Ty) -> bool {
223-
if let TyKind::Path(ref path) = ty.node {
224-
match_qpath(path, &paths::LINT_ARRAY)
225-
} else {
226-
false
227-
}
228+
false
228229
}
229230

230231
struct LintCollector<'a, 'tcx: 'a> {

clippy_lints/src/utils/paths.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub const ITERATOR: [&str; 4] = ["core", "iter", "iterator", "Iterator"];
5656
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
5757
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
5858
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];
59-
pub const LINT_ARRAY: [&str; 3] = ["rustc", "lint", "LintArray"];
59+
pub const LINT_PASS: [&str; 3] = ["rustc", "lint", "LintPass"];
6060
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
6161
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
6262
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];

tests/ui/lint_without_lint_pass.rs

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

0 commit comments

Comments
 (0)