Skip to content

Commit b16a534

Browse files
committed
Warn when clippy::restriction is enabled via the command line
1 parent 8e19251 commit b16a534

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

clippy_lints/src/attrs.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
1313
};
14-
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
14+
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext};
1515
use rustc_middle::lint::in_external_macro;
1616
use rustc_middle::ty;
1717
use rustc_semver::RustcVersion;
1818
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1919
use rustc_span::source_map::Span;
20-
use rustc_span::sym;
2120
use rustc_span::symbol::Symbol;
21+
use rustc_span::{sym, DUMMY_SP};
2222
use semver::Version;
2323

2424
static UNIX_SYSTEMS: &[&str] = &[
@@ -303,6 +303,26 @@ declare_lint_pass!(Attributes => [
303303
]);
304304

305305
impl<'tcx> LateLintPass<'tcx> for Attributes {
306+
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
307+
for (name, level) in &cx.sess().opts.lint_opts {
308+
if name == "clippy::restriction" && *level > Level::Allow {
309+
span_lint_and_then(
310+
cx,
311+
BLANKET_CLIPPY_RESTRICTION_LINTS,
312+
DUMMY_SP,
313+
"`clippy::restriction` is not meant to be enabled as a group",
314+
|diag| {
315+
diag.note(format!(
316+
"because of the command line `--{} clippy::restriction`",
317+
level.as_str()
318+
));
319+
diag.help("enable the restriction lints you need individually");
320+
},
321+
);
322+
}
323+
}
324+
}
325+
306326
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
307327
if let Some(items) = &attr.meta_item_list() {
308328
if let Some(ident) = attr.ident() {
@@ -441,9 +461,9 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe
441461
cx,
442462
BLANKET_CLIPPY_RESTRICTION_LINTS,
443463
lint.span(),
444-
"restriction lints are not meant to be all enabled",
464+
"`clippy::restriction` is not meant to be enabled as a group",
445465
None,
446-
"try enabling only the lints you really need",
466+
"enable the restriction lints you need individually",
447467
);
448468
}
449469
}

tests/ui/blanket_clippy_restriction_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -W clippy::restriction
2+
13
#![warn(clippy::blanket_clippy_restriction_lints)]
24

35
//! Test that the whole restriction group is not enabled
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
error: restriction lints are not meant to be all enabled
2-
--> $DIR/blanket_clippy_restriction_lints.rs:4:9
1+
error: `clippy::restriction` is not meant to be enabled as a group
2+
|
3+
= note: because of the command line `--warn clippy::restriction`
4+
= help: enable the restriction lints you need individually
5+
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
6+
7+
error: `clippy::restriction` is not meant to be enabled as a group
8+
--> $DIR/blanket_clippy_restriction_lints.rs:6:9
39
|
410
LL | #![warn(clippy::restriction)]
511
| ^^^^^^^^^^^^^^^^^^^
612
|
7-
= help: try enabling only the lints you really need
8-
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
13+
= help: enable the restriction lints you need individually
914

10-
error: restriction lints are not meant to be all enabled
11-
--> $DIR/blanket_clippy_restriction_lints.rs:5:9
15+
error: `clippy::restriction` is not meant to be enabled as a group
16+
--> $DIR/blanket_clippy_restriction_lints.rs:7:9
1217
|
1318
LL | #![deny(clippy::restriction)]
1419
| ^^^^^^^^^^^^^^^^^^^
1520
|
16-
= help: try enabling only the lints you really need
21+
= help: enable the restriction lints you need individually
1722

18-
error: restriction lints are not meant to be all enabled
19-
--> $DIR/blanket_clippy_restriction_lints.rs:6:11
23+
error: `clippy::restriction` is not meant to be enabled as a group
24+
--> $DIR/blanket_clippy_restriction_lints.rs:8:11
2025
|
2126
LL | #![forbid(clippy::restriction)]
2227
| ^^^^^^^^^^^^^^^^^^^
2328
|
24-
= help: try enabling only the lints you really need
29+
= help: enable the restriction lints you need individually
2530

26-
error: aborting due to 3 previous errors
31+
error: aborting due to 4 previous errors
2732

0 commit comments

Comments
 (0)