Skip to content

Commit 8e0de3d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into prs
2 parents 205db6f + 131c8f8 commit 8e0de3d

File tree

545 files changed

+4014
-3797
lines changed

Some content is hidden

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

545 files changed

+4014
-3797
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
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
// ...
@@ -185,7 +185,7 @@ It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerate
185185
```rust
186186
// ./clippy_lints/src/else_if_without_else.rs
187187

188-
use rustc::lint::*;
188+
use rustc::lint::{EarlyLintPass, LintArray, LintPass};
189189

190190
// ...
191191

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ regex = "1"
4646
semver = "0.9"
4747

4848
[dev-dependencies]
49-
cargo_metadata = "0.5"
49+
cargo_metadata = "0.6"
5050
compiletest_rs = "0.3.7"
5151
lazy_static = "1.0"
5252
serde_derive = "1.0"
@@ -59,9 +59,5 @@ derive-new = "0.5"
5959
# for more information.
6060
rustc-workspace-hack = "1.0.0"
6161

62-
[build-dependencies]
63-
rustc_version = "0.2.2"
64-
ansi_term = "0.11"
65-
6662
[features]
6763
debugging = []

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

build.rs

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,98 +13,11 @@
1313
//! This build script was originally taken from the Rocket web framework:
1414
//! https://github.com/SergioBenitez/Rocket
1515
16-
use ansi_term::Colour::Red;
17-
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
1816
use std::env;
1917

2018
fn main() {
21-
check_rustc_version();
22-
2319
// Forward the profile to the main compilation
2420
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
2521
// Don't rebuild even if nothing changed
2622
println!("cargo:rerun-if-changed=build.rs");
2723
}
28-
29-
fn check_rustc_version() {
30-
let string = include_str!("min_version.txt");
31-
let min_version_meta = version_meta_for(string).expect("Could not parse version string in min_version.txt");
32-
let current_version_meta = version_meta().expect("Could not retrieve current rustc version information from ENV");
33-
34-
let min_version = min_version_meta.clone().semver;
35-
let min_date_str = min_version_meta
36-
.clone()
37-
.commit_date
38-
.expect("min_version.txt does not contain a rustc commit date");
39-
40-
// Dev channel (rustc built from git) does not have any date or commit information in rustc -vV
41-
// `current_version_meta.commit_date` would crash, so we return early here.
42-
if current_version_meta.channel == Channel::Dev {
43-
return;
44-
}
45-
46-
let current_version = current_version_meta.clone().semver;
47-
let current_date_str = current_version_meta
48-
.clone()
49-
.commit_date
50-
.expect("current rustc version information does not contain a rustc commit date");
51-
52-
let print_version_err = |version: &Version, date: &str| {
53-
eprintln!(
54-
"> {} {}. {} {}.\n",
55-
"Installed rustc version is:",
56-
format!("{} ({})", version, date),
57-
"Minimum required rustc version:",
58-
format!("{} ({})", min_version, min_date_str)
59-
);
60-
};
61-
62-
if !correct_channel(&current_version_meta) {
63-
eprintln!(
64-
"\n{} {}",
65-
Red.bold().paint("error:"),
66-
"Clippy requires a nightly version of Rust."
67-
);
68-
print_version_err(&current_version, &*current_date_str);
69-
eprintln!(
70-
"{}{}{}",
71-
"See the README (", "https://github.com/rust-lang-nursery/rust-clippy#usage", ") for more information."
72-
);
73-
panic!("Aborting compilation due to incompatible compiler.")
74-
}
75-
76-
let current_date = str_to_ymd(&current_date_str).unwrap();
77-
let min_date = str_to_ymd(&min_date_str).unwrap();
78-
79-
if current_date < min_date {
80-
eprintln!(
81-
"\n{} {}",
82-
Red.bold().paint("error:"),
83-
"Clippy does not support this version of rustc nightly."
84-
);
85-
eprintln!(
86-
"> {}{}{}",
87-
"Use `", "rustup update", "` or your preferred method to update Rust."
88-
);
89-
print_version_err(&current_version, &*current_date_str);
90-
panic!("Aborting compilation due to incompatible compiler.")
91-
}
92-
}
93-
94-
fn correct_channel(version_meta: &VersionMeta) -> bool {
95-
match version_meta.channel {
96-
Channel::Stable | Channel::Beta => false,
97-
Channel::Nightly | Channel::Dev => true,
98-
}
99-
}
100-
101-
/// Convert a string of %Y-%m-%d to a single u32 maintaining ordering.
102-
fn str_to_ymd(ymd: &str) -> Option<u32> {
103-
let ymd: Vec<u32> = ymd.split("-").filter_map(|s| s.parse::<u32>().ok()).collect();
104-
if ymd.len() != 3 {
105-
return None;
106-
}
107-
108-
let (y, m, d) = (ymd[0], ymd[1], ymd[2]);
109-
Some((y << 9) | (m << 5) | d)
110-
}

ci/base-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ remark -f *.md > /dev/null
77
# build clippy in debug mode and run tests
88
cargo build --features debugging
99
cargo test --features debugging
10+
cd clippy_lints && cargo test && cd ..
1011
mkdir -p ~/rust/cargo/bin
1112
cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy
1213
cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ keywords = ["clippy", "lint", "plugin"]
1919
edition = "2018"
2020

2121
[dependencies]
22-
cargo_metadata = "0.5"
22+
cargo_metadata = "0.6"
2323
itertools = "0.7"
2424
lazy_static = "1.0.2"
2525
matches = "0.1.7"

clippy_lints/src/approx_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
3-
use rustc::lint::*;
4-
use rustc::{declare_lint, lint_array};
3+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir;
3-
use rustc::lint::*;
4-
use rustc::{declare_lint, lint_array};
3+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
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: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,11 @@ use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_an
22
use crate::utils::{higher, sugg};
33
use rustc::hir;
44
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
5-
use rustc::lint::*;
6-
use rustc::{declare_lint, lint_array};
5+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
6+
use rustc::{declare_tool_lint, lint_array};
77
use if_chain::if_chain;
88
use syntax::ast;
99

10-
/// **What it does:** Checks for compound assignment operations (`+=` and
11-
/// similar).
12-
///
13-
/// **Why is this bad?** Projects with many developers from languages without
14-
/// those operations may find them unreadable and not worth their weight.
15-
///
16-
/// **Known problems:** Types implementing `OpAssign` don't necessarily
17-
/// implement `Op`.
18-
///
19-
/// **Example:**
20-
/// ```rust
21-
/// a += 1;
22-
/// ```
23-
declare_clippy_lint! {
24-
pub ASSIGN_OPS,
25-
restriction,
26-
"any compound assignment operation"
27-
}
28-
2910
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
3011
/// patterns.
3112
///
@@ -73,24 +54,14 @@ pub struct AssignOps;
7354

7455
impl LintPass for AssignOps {
7556
fn get_lints(&self) -> LintArray {
76-
lint_array!(ASSIGN_OPS, ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
57+
lint_array!(ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
7758
}
7859
}
7960

8061
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8162
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
8263
match expr.node {
8364
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
84-
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
85-
let lhs = &sugg::Sugg::hir(cx, lhs, "..");
86-
let rhs = &sugg::Sugg::hir(cx, rhs, "..");
87-
88-
db.span_suggestion(
89-
expr.span,
90-
"replace it with",
91-
format!("{} = {}", lhs, sugg::make_binop(higher::binop(op.node), lhs, rhs)),
92-
);
93-
});
9465
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
9566
if op.node == binop.node {
9667
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
@@ -137,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
137108
},
138109
hir::ExprKind::Assign(ref assignee, ref e) => {
139110
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
140-
#[allow(cyclomatic_complexity)]
111+
#[allow(clippy::cyclomatic_complexity)]
141112
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
142113
let ty = cx.tables.expr_ty(assignee);
143114
let rty = cx.tables.expr_ty(rhs);
@@ -162,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
162133
// the crate node is the only one that is not in the map
163134
if_chain! {
164135
if parent_impl != ast::CRATE_NODE_ID;
165-
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
136+
if let hir::Node::Item(item) = cx.tcx.hir.get(parent_impl);
166137
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
167138
item.node;
168139
if trait_ref.path.def.def_id() == trait_id;

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::utils::{
66
without_block_comments,
77
};
88
use rustc::hir::*;
9-
use rustc::lint::*;
10-
use rustc::{declare_lint, lint_array};
9+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
2-
use rustc::lint::*;
3-
use rustc::{declare_lint, lint_array};
2+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc::lint::*;
2-
use rustc::{declare_lint, lint_array};
1+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
2-
use rustc::lint::*;
3-
use rustc::{declare_lint, lint_array};
2+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
3+
use rustc::{declare_tool_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty;
66
use syntax::ast::{Name, UintTy};
@@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
6565
_ => { return; }
6666
}
6767
};
68-
if ty::TyUint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).sty {
68+
if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).sty {
6969
return;
7070
}
7171
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =

0 commit comments

Comments
 (0)