Skip to content

Commit c81d70e

Browse files
authored
Merge pull request #2977 from flip1995/tool_lints
Implement tool_lints
2 parents 73e8416 + 9abf6fc commit c81d70e

File tree

525 files changed

+2960
-2839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

525 files changed

+2960
-2839
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
170170
reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
171171
// ...
172172

173-
reg.register_lint_group("clippy_restriction", vec![
173+
reg.register_lint_group("clippy::restriction", vec![
174174
// ...
175175
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
176176
// ...

README.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g
1313

1414
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1515

16-
* `clippy` (everything that has no false positives)
17-
* `clippy_pedantic` (everything)
18-
* `clippy_nursery` (new lints that aren't quite ready yet)
19-
* `clippy_style` (code that should be written in a more idiomatic way)
20-
* `clippy_complexity` (code that does something simple but in a complex way)
21-
* `clippy_perf` (code that can be written in a faster way)
22-
* `clippy_cargo` (checks against the cargo manifest)
23-
* **`clippy_correctness`** (code that is just outright wrong or very very useless)
16+
* `clippy::all` (everything that has no false positives)
17+
* `clippy::pedantic` (everything)
18+
* `clippy::nursery` (new lints that aren't quite ready yet)
19+
* `clippy::style` (code that should be written in a more idiomatic way)
20+
* `clippy::complexity` (code that does something simple but in a complex way)
21+
* `clippy::perf` (code that can be written in a faster way)
22+
* `clippy::cargo` (checks against the cargo manifest)
23+
* **`clippy::correctness`** (code that is just outright wrong or very very useless)
2424

2525
More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas!
2626

@@ -106,26 +106,18 @@ define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable.
106106

107107
You can add options to `allow`/`warn`/`deny`:
108108

109-
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
109+
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`)
110110

111-
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
112-
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
111+
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
112+
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive
113113
lints prone to false positives.
114114

115-
* only some lints (`#![deny(single_match, box_vec)]`, etc)
115+
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc)
116116

117117
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
118118

119119
Note: `deny` produces errors instead of warnings.
120120

121-
For convenience, `cargo clippy` automatically defines a `cargo-clippy`
122-
feature. This lets you set lint levels and compile with or without Clippy
123-
transparently:
124-
125-
```rust
126-
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
127-
```
128-
129121
## Updating rustc
130122

131123
Sometimes, rustc moves forward without Clippy catching up. Therefore updating

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use std::f64::consts as f64;
66
use syntax::ast::{FloatTy, Lit, LitKind};
77
use syntax::symbol;

clippy_lints/src/arithmetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use syntax::source_map::Span;
66

77
/// **What it does:** Checks for plain integer arithmetic.

clippy_lints/src/assign_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::{higher, sugg};
33
use rustc::hir;
44
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
6-
use rustc::{declare_lint, lint_array};
6+
use rustc::{declare_tool_lint, lint_array};
77
use if_chain::if_chain;
88
use syntax::ast;
99

@@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
108108
},
109109
hir::ExprKind::Assign(ref assignee, ref e) => {
110110
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
111-
#[allow(cyclomatic_complexity)]
111+
#[allow(clippy::cyclomatic_complexity)]
112112
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
113113
let ty = cx.tables.expr_ty(assignee);
114114
let rty = cx.tables.expr_ty(rhs);

clippy_lints/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::utils::{
77
};
88
use rustc::hir::*;
99
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
10-
use rustc::{declare_lint, lint_array};
10+
use rustc::{declare_tool_lint, lint_array};
1111
use if_chain::if_chain;
1212
use rustc::ty::{self, TyCtxt};
1313
use semver::Version;

clippy_lints/src/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use if_chain::if_chain;
55
use syntax::ast::LitKind;
66
use syntax::source_map::Span;

clippy_lints/src/blacklisted_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2-
use rustc::{declare_lint, lint_array};
2+
use rustc::{declare_tool_lint, lint_array};
33
use rustc::hir::*;
44
use crate::utils::span_lint;
55

clippy_lints/src/block_in_if_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use matches::matches;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use rustc::hir::*;
55
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
66
use crate::utils::*;

clippy_lints/src/booleans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2-
use rustc::{declare_lint, lint_array};
2+
use rustc::{declare_tool_lint, lint_array};
33
use rustc::hir::*;
44
use rustc::hir::intravisit::*;
55
use syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID};
@@ -118,7 +118,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
118118
}
119119
for (n, expr) in self.terminals.iter().enumerate() {
120120
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) {
121-
#[allow(cast_possible_truncation)]
121+
#[allow(clippy::cast_possible_truncation)]
122122
return Ok(Bool::Term(n as u8));
123123
}
124124
let negated = match e.node {
@@ -150,14 +150,14 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
150150
_ => continue,
151151
};
152152
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
153-
#[allow(cast_possible_truncation)]
153+
#[allow(clippy::cast_possible_truncation)]
154154
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
155155
}
156156
}
157157
let n = self.terminals.len();
158158
self.terminals.push(e);
159159
if n < 32 {
160-
#[allow(cast_possible_truncation)]
160+
#[allow(clippy::cast_possible_truncation)]
161161
Ok(Bool::Term(n as u8))
162162
} else {
163163
Err("too many literals".to_owned())

clippy_lints/src/bytecount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty;
66
use syntax::ast::{Name, UintTy};

clippy_lints/src/collapsible_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! This lint is **warn** by default
1414
1515
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
16-
use rustc::{declare_lint, lint_array};
16+
use rustc::{declare_tool_lint, lint_array};
1717
use if_chain::if_chain;
1818
use syntax::ast;
1919

clippy_lints/src/const_static_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::ast::*;
22
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use crate::utils::{in_macro, snippet, span_lint_and_then};
55

66
/// **What it does:** Checks for constants with an explicit `'static` lifetime.

clippy_lints/src/consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![allow(cast_possible_truncation)]
2-
#![allow(float_cmp)]
1+
#![allow(clippy::float_cmp)]
32

43
use rustc::lint::LateContext;
54
use rustc::{span_bug, bug};

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2-
use rustc::{declare_lint, lint_array};
2+
use rustc::{declare_tool_lint, lint_array};
33
use rustc::ty::Ty;
44
use rustc::hir::*;
55
use std::collections::HashMap;

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{is_copy, match_path, paths, span_note_and_lint};
22
use rustc::hir::{Item, ItemKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55

66
/// **What it does:** Checks for types that implement `Copy` as well as
77
/// `Iterator`.

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc::cfg::CFG;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass, LintContext};
5-
use rustc::{declare_lint, lint_array};
5+
use rustc::{declare_tool_lint, lint_array};
66
use rustc::hir::*;
77
use rustc::ty;
88
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
@@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> {
186186
}
187187

188188
#[cfg(feature = "debugging")]
189-
#[allow(too_many_arguments)]
189+
#[allow(clippy::too_many_arguments)]
190190
fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) {
191191
span_bug!(
192192
span,
@@ -200,7 +200,7 @@ fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts:
200200
);
201201
}
202202
#[cfg(not(feature = "debugging"))]
203-
#[allow(too_many_arguments)]
203+
#[allow(clippy::too_many_arguments)]
204204
fn report_cc_bug(cx: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) {
205205
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
206206
cx.sess().span_note_without_error(

clippy_lints/src/default_trait_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty::TyKind;
66

clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2-
use rustc::{declare_lint, lint_array};
2+
use rustc::{declare_tool_lint, lint_array};
33
use if_chain::if_chain;
44
use rustc::ty::{self, Ty};
55
use rustc::hir::*;

clippy_lints/src/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use itertools::Itertools;
22
use pulldown_cmark;
33
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use syntax::ast;
66
use syntax::source_map::{BytePos, Span};
77
use syntax_pos::Pos;
@@ -86,7 +86,7 @@ impl<'a> Iterator for Parser<'a> {
8686
/// `syntax::parse::lexer::comments::strip_doc_comment_decoration` because we
8787
/// need to keep track of
8888
/// the spans but this function is inspired from the later.
89-
#[allow(cast_possible_truncation)]
89+
#[allow(clippy::cast_possible_truncation)]
9090
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
9191
// one-line comments lose their prefix
9292
const ONELINERS: &[&str] = &["///!", "///", "//!", "//"];

clippy_lints/src/double_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_lint, lint_array};
5+
use rustc::{declare_tool_lint, lint_array};
66
use syntax::source_map::Span;
77

88
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};

clippy_lints/src/double_parens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::ast::*;
22
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44

55
/// **What it does:** Checks for unnecessary double parentheses.
66
///

clippy_lints/src/drop_forget_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2-
use rustc::{declare_lint, lint_array};
2+
use rustc::{declare_tool_lint, lint_array};
33
use if_chain::if_chain;
44
use rustc::ty;
55
use rustc::hir::*;

clippy_lints/src/duration_subsec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use if_chain::if_chain;
55
use syntax::source_map::Spanned;
66

clippy_lints/src/else_if_without_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on if expressions with an else if, but without a final else branch
22
33
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, in_external_macro, LintContext};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use syntax::ast::*;
66

77
use crate::utils::span_lint_and_sugg;

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint when there is an enum with no variants
22
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use rustc::hir::*;
66
use crate::utils::span_lint_and_then;
77

clippy_lints/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::hir::*;
22
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use if_chain::if_chain;
66
use syntax::source_map::Span;
77
use crate::utils::SpanlessEq;

clippy_lints/src/enum_clike.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! don't fit into an `i32`
33
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_lint, lint_array};
5+
use rustc::{declare_tool_lint, lint_array};
66
use rustc::hir::*;
77
use rustc::ty;
88
use rustc::ty::subst::Substs;
@@ -43,7 +43,7 @@ impl LintPass for UnportableVariant {
4343
}
4444

4545
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
46-
#[allow(cast_possible_truncation, cast_sign_loss)]
46+
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
4747
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
4848
if cx.tcx.data_layout.pointer_size.bits() != 64 {
4949
return;

clippy_lints/src/enum_glob_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc::hir::*;
44
use rustc::hir::def::Def;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
6-
use rustc::{declare_lint, lint_array};
6+
use rustc::{declare_tool_lint, lint_array};
77
use syntax::ast::NodeId;
88
use syntax::source_map::Span;
99
use crate::utils::span_lint;

clippy_lints/src/enum_variants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on enum variants that are prefixed or suffixed by the same characters
22
33
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, Lint};
4-
use rustc::{declare_lint, lint_array};
4+
use rustc::{declare_tool_lint, lint_array};
55
use syntax::ast::*;
66
use syntax::source_map::Span;
77
use syntax::symbol::LocalInternedString;
@@ -147,7 +147,7 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
147147
}
148148

149149
// FIXME: #600
150-
#[allow(while_let_on_iterator)]
150+
#[allow(clippy::while_let_on_iterator)]
151151
fn check_variant(
152152
cx: &EarlyContext<'_>,
153153
threshold: u64,

clippy_lints/src/eq_op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3-
use rustc::{declare_lint, lint_array};
3+
use rustc::{declare_tool_lint, lint_array};
44
use crate::utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
55

66
/// **What it does:** Checks for equal operands to comparison, logical and
@@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
8383
BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => (cx.tcx.lang_items().ord_trait(), true),
8484
};
8585
if let Some(trait_id) = trait_id {
86-
#[allow(match_same_arms)]
86+
#[allow(clippy::match_same_arms)]
8787
match (&left.node, &right.node) {
8888
// do not suggest to dereference literals
8989
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},

0 commit comments

Comments
 (0)