Warn when clippy::restriction is enabled via the command line

This commit is contained in:
Alex Macleod 2022-10-30 21:15:46 +00:00
parent 8e19251366
commit b16a534618
3 changed files with 42 additions and 15 deletions

View File

@ -11,14 +11,14 @@ use rustc_errors::Applicability;
use rustc_hir::{
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
};
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
use rustc_semver::RustcVersion;
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
use rustc_span::{sym, DUMMY_SP};
use semver::Version;
static UNIX_SYSTEMS: &[&str] = &[
@ -303,6 +303,26 @@ declare_lint_pass!(Attributes => [
]);
impl<'tcx> LateLintPass<'tcx> for Attributes {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
for (name, level) in &cx.sess().opts.lint_opts {
if name == "clippy::restriction" && *level > Level::Allow {
span_lint_and_then(
cx,
BLANKET_CLIPPY_RESTRICTION_LINTS,
DUMMY_SP,
"`clippy::restriction` is not meant to be enabled as a group",
|diag| {
diag.note(format!(
"because of the command line `--{} clippy::restriction`",
level.as_str()
));
diag.help("enable the restriction lints you need individually");
},
);
}
}
}
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident() {
@ -441,9 +461,9 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe
cx,
BLANKET_CLIPPY_RESTRICTION_LINTS,
lint.span(),
"restriction lints are not meant to be all enabled",
"`clippy::restriction` is not meant to be enabled as a group",
None,
"try enabling only the lints you really need",
"enable the restriction lints you need individually",
);
}
}

View File

@ -1,3 +1,5 @@
// compile-flags: -W clippy::restriction
#![warn(clippy::blanket_clippy_restriction_lints)]
//! Test that the whole restriction group is not enabled

View File

@ -1,27 +1,32 @@
error: restriction lints are not meant to be all enabled
--> $DIR/blanket_clippy_restriction_lints.rs:4:9
error: `clippy::restriction` is not meant to be enabled as a group
|
= note: because of the command line `--warn clippy::restriction`
= help: enable the restriction lints you need individually
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
error: `clippy::restriction` is not meant to be enabled as a group
--> $DIR/blanket_clippy_restriction_lints.rs:6:9
|
LL | #![warn(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: try enabling only the lints you really need
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
= help: enable the restriction lints you need individually
error: restriction lints are not meant to be all enabled
--> $DIR/blanket_clippy_restriction_lints.rs:5:9
error: `clippy::restriction` is not meant to be enabled as a group
--> $DIR/blanket_clippy_restriction_lints.rs:7:9
|
LL | #![deny(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: try enabling only the lints you really need
= help: enable the restriction lints you need individually
error: restriction lints are not meant to be all enabled
--> $DIR/blanket_clippy_restriction_lints.rs:6:11
error: `clippy::restriction` is not meant to be enabled as a group
--> $DIR/blanket_clippy_restriction_lints.rs:8:11
|
LL | #![forbid(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: try enabling only the lints you really need
= help: enable the restriction lints you need individually
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors