Fix lint_without_lint_pass
This commit is contained in:
@@ -48,6 +48,7 @@ use toml;
|
|||||||
|
|
||||||
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
|
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
|
||||||
// as said in the README.md of this repository. If this changes, please update README.md.
|
// as said in the README.md of this repository. If this changes, please update README.md.
|
||||||
|
#[macro_export]
|
||||||
macro_rules! declare_clippy_lint {
|
macro_rules! declare_clippy_lint {
|
||||||
{ pub $name:tt, style, $description:tt } => {
|
{ pub $name:tt, style, $description:tt } => {
|
||||||
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
|
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
|
||||||
|
|||||||
@@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
|
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
match_qpath, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
|
match_def_path, match_qpath, match_type, 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 crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
|
use crate::rustc::hir::def::Def;
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
@@ -161,7 +162,8 @@ impl LintPass for LintWithoutLintPass {
|
|||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
|
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
|
||||||
if is_lint_ref_type(ty) {
|
|
||||||
|
if is_lint_ref_type(cx, ty) {
|
||||||
self.declared_lints.insert(item.name, item.span);
|
self.declared_lints.insert(item.name, item.span);
|
||||||
} else if is_lint_array_type(ty) && item.name == "ARRAY" {
|
} else if is_lint_array_type(ty) && item.name == "ARRAY" {
|
||||||
if let VisibilityKind::Inherited = item.vis.node {
|
if let VisibilityKind::Inherited = item.vis.node {
|
||||||
@@ -203,19 +205,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_lint_ref_type(ty: &Ty) -> bool {
|
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
|
||||||
if let TyKind::Rptr(
|
if let TyKind::Rptr(
|
||||||
_,
|
_,
|
||||||
MutTy {
|
MutTy {
|
||||||
ty: ref inner,
|
ty: ref inner,
|
||||||
mutbl: MutImmutable,
|
mutbl: MutImmutable,
|
||||||
},
|
},
|
||||||
) = ty.node
|
) = ty.node {
|
||||||
{
|
|
||||||
if let TyKind::Path(ref path) = inner.node {
|
if let TyKind::Path(ref path) = inner.node {
|
||||||
return match_qpath(path, &paths::LINT);
|
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
|
||||||
|
return match_def_path(cx.tcx, def_id, &paths::LINT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
tests/ui/lint_without_lint_pass.rs
Normal file
19
tests/ui/lint_without_lint_pass.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#![deny(clippy::internal)]
|
||||||
|
|
||||||
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rustc;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate clippy_lints;
|
||||||
|
|
||||||
|
declare_clippy_lint!
|
||||||
|
{
|
||||||
|
pub TEST_LINT,
|
||||||
|
correctness,
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
||||||
21
tests/ui/lint_without_lint_pass.stderr
Normal file
21
tests/ui/lint_without_lint_pass.stderr
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
error: the lint `TEST_LINT` is not added to any `LintPass`
|
||||||
|
--> $DIR/lint_without_lint_pass.rs:11:1
|
||||||
|
|
|
||||||
|
11 | / declare_clippy_lint!
|
||||||
|
12 | | {
|
||||||
|
13 | | pub TEST_LINT,
|
||||||
|
14 | | correctness,
|
||||||
|
15 | | ""
|
||||||
|
16 | | }
|
||||||
|
| |_^
|
||||||
|
|
|
||||||
|
note: lint level defined here
|
||||||
|
--> $DIR/lint_without_lint_pass.rs:1:9
|
||||||
|
|
|
||||||
|
1 | #![deny(clippy::internal)]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
= note: #[deny(clippy::lint_without_lint_pass)] implied by #[deny(clippy::internal)]
|
||||||
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
Reference in New Issue
Block a user