Skip to content

Commit

Permalink
Merge pull request #2977 from flip1995/tool_lints
Browse files Browse the repository at this point in the history
Implement tool_lints
  • Loading branch information
Manishearth authored Sep 1, 2018
2 parents 73e8416 + 9abf6fc commit c81d70e
Show file tree
Hide file tree
Showing 525 changed files with 2,960 additions and 2,839 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
// ...

reg.register_lint_group("clippy_restriction", vec![
reg.register_lint_group("clippy::restriction", vec![
// ...
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
// ...
Expand Down
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g

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

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

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

Expand Down Expand Up @@ -106,26 +106,18 @@ define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable.

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

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

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

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

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

Note: `deny` produces errors instead of warnings.

For convenience, `cargo clippy` automatically defines a `cargo-clippy`
feature. This lets you set lint levels and compile with or without Clippy
transparently:

```rust
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
```

## Updating rustc

Sometimes, rustc moves forward without Clippy catching up. Therefore updating
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::span_lint;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use std::f64::consts as f64;
use syntax::ast::{FloatTy, Lit, LitKind};
use syntax::symbol;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::span_lint;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;

/// **What it does:** Checks for plain integer arithmetic.
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::utils::{higher, sugg};
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use syntax::ast;

Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
},
hir::ExprKind::Assign(ref assignee, ref e) => {
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
#[allow(cyclomatic_complexity)]
#[allow(clippy::cyclomatic_complexity)]
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
let ty = cx.tables.expr_ty(assignee);
let rty = cx.tables.expr_ty(rhs);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::utils::{
};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use rustc::ty::{self, TyCtxt};
use semver::Version;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use syntax::ast::LitKind;
use syntax::source_map::Span;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use crate::utils::span_lint;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/block_in_if_condition.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use matches::matches;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use crate::utils::*;
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use rustc::hir::intravisit::*;
use syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID};
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
}
for (n, expr) in self.terminals.iter().enumerate() {
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) {
#[allow(cast_possible_truncation)]
#[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Term(n as u8));
}
let negated = match e.node {
Expand Down Expand Up @@ -150,14 +150,14 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
_ => continue,
};
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
#[allow(cast_possible_truncation)]
#[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
}
}
let n = self.terminals.len();
self.terminals.push(e);
if n < 32 {
#[allow(cast_possible_truncation)]
#[allow(clippy::cast_possible_truncation)]
Ok(Bool::Term(n as u8))
} else {
Err("too many literals".to_owned())
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use rustc::ty;
use syntax::ast::{Name, UintTy};
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! This lint is **warn** by default
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use syntax::ast;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/const_static_lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use syntax::ast::*;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use crate::utils::{in_macro, snippet, span_lint_and_then};

/// **What it does:** Checks for constants with an explicit `'static` lifetime.
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(cast_possible_truncation)]
#![allow(float_cmp)]
#![allow(clippy::float_cmp)]

use rustc::lint::LateContext;
use rustc::{span_bug, bug};
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::ty::Ty;
use rustc::hir::*;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copy_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::{is_copy, match_path, paths, span_note_and_lint};
use rustc::hir::{Item, ItemKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};

/// **What it does:** Checks for types that implement `Copy` as well as
/// `Iterator`.
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use rustc::cfg::CFG;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass, LintContext};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use rustc::ty;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> {
}

#[cfg(feature = "debugging")]
#[allow(too_many_arguments)]
#[allow(clippy::too_many_arguments)]
fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) {
span_bug!(
span,
Expand All @@ -200,7 +200,7 @@ fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts:
);
}
#[cfg(not(feature = "debugging"))]
#[allow(too_many_arguments)]
#[allow(clippy::too_many_arguments)]
fn report_cc_bug(cx: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) {
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
cx.sess().span_note_without_error(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/default_trait_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use rustc::ty::TyKind;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use rustc::ty::{self, Ty};
use rustc::hir::*;
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use itertools::Itertools;
use pulldown_cmark;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
use syntax::source_map::{BytePos, Span};
use syntax_pos::Pos;
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'a> Iterator for Parser<'a> {
/// `syntax::parse::lexer::comments::strip_doc_comment_decoration` because we
/// need to keep track of
/// the spans but this function is inspired from the later.
#[allow(cast_possible_truncation)]
#[allow(clippy::cast_possible_truncation)]
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
// one-line comments lose their prefix
const ONELINERS: &[&str] = &["///!", "///", "//!", "//"];
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;

use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use syntax::ast::*;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};

/// **What it does:** Checks for unnecessary double parentheses.
///
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/drop_forget_ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use rustc::ty;
use rustc::hir::*;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/duration_subsec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use syntax::source_map::Spanned;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/else_if_without_else.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! lint on if expressions with an else if, but without a final else branch
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, in_external_macro, LintContext};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::*;

use crate::utils::span_lint_and_sugg;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/empty_enum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! lint when there is an enum with no variants
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use crate::utils::span_lint_and_then;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc::hir::*;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
use syntax::source_map::Span;
use crate::utils::SpanlessEq;
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! don't fit into an `i32`
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir::*;
use rustc::ty;
use rustc::ty::subst::Substs;
Expand Down Expand Up @@ -43,7 +43,7 @@ impl LintPass for UnportableVariant {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
#[allow(cast_possible_truncation, cast_sign_loss)]
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if cx.tcx.data_layout.pointer_size.bits() != 64 {
return;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/enum_glob_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use rustc::hir::*;
use rustc::hir::def::Def;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::NodeId;
use syntax::source_map::Span;
use crate::utils::span_lint;
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! lint on enum variants that are prefixed or suffixed by the same characters
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, Lint};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::*;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;
Expand Down Expand Up @@ -147,7 +147,7 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
}

// FIXME: #600
#[allow(while_let_on_iterator)]
#[allow(clippy::while_let_on_iterator)]
fn check_variant(
cx: &EarlyContext<'_>,
threshold: u64,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint, lint_array};
use rustc::{declare_tool_lint, lint_array};
use crate::utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};

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

0 comments on commit c81d70e

Please sign in to comment.