Skip to content

Commit 847e4dc

Browse files
author
Michael Wright
committed
Merge branch 'master' into issue2894
2 parents b90fc5e + f27aaac commit 847e4dc

File tree

114 files changed

+1417
-1341
lines changed

Some content is hidden

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

114 files changed

+1417
-1341
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ a `.stdout` file with the generated code:
9393
// ./tests/ui/my_lint.stdout
9494

9595
if_chain! {
96-
if let Expr_::ExprArray(ref elements) = stmt.node;
96+
if let ExprKind::Array(ref elements) = stmt.node;
9797
if elements.len() == 1;
98-
if let Expr_::ExprLit(ref lit) = elements[0].node;
98+
if let ExprKind::Lit(ref lit) = elements[0].node;
9999
if let LitKind::Int(7, _) = lit.node;
100100
then {
101101
// report your lint here
@@ -179,7 +179,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
179179
```
180180

181181
The [`rustc_plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
182-
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
182+
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
183183
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/update_lints.py` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
184184

185185
```rust

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,46 @@ Table of contents:
3535
Since this is a tool for helping the developer of a library or application
3636
write better code, it is recommended not to include Clippy as a hard dependency.
3737
Options include using it as an optional dependency, as a cargo subcommand, or
38-
as an included feature during build. All of these options are detailed below.
38+
as an included feature during build. These options are detailed below.
3939

40-
As a general rule Clippy will only work with the *latest* Rust nightly for now.
40+
### As a cargo subcommand (`cargo clippy`)
4141

42-
To install Rust nightly, the recommended way is to use [rustup](https://rustup.rs/):
42+
One way to use Clippy is by installing Clippy through rustup as a cargo
43+
subcommand.
4344

44-
```terminal
45-
rustup install nightly
46-
```
45+
#### Step 1: Install rustup
4746

48-
### As a cargo subcommand (`cargo clippy`)
47+
You can install [rustup](http://rustup.rs/) on supported platforms. This will help
48+
us install clippy and its dependencies.
4949

50-
One way to use Clippy is by installing Clippy through cargo as a cargo
51-
subcommand.
50+
If you already have rustup installed, update to ensure you have the latest
51+
rustup and compiler:
5252

5353
```terminal
54-
cargo +nightly install clippy
54+
rustup update
5555
```
5656

57-
(The `+nightly` is not necessary if your default `rustup` install is nightly)
57+
#### Step 2: Install nightly toolchain
5858

59-
Now you can run Clippy by invoking `cargo +nightly clippy`.
59+
Rustup integration is still new, you will need a relatively new nightly (2018-07-15 or later).
6060

61-
To update the subcommand together with the latest nightly use the [rust-update](rust-update) script or run:
61+
To install Rust nightly with [rustup](https://rustup.rs/):
6262

6363
```terminal
64-
rustup update nightly
65-
cargo +nightly install --force clippy
64+
rustup install nightly
6665
```
6766

68-
In case you are not using rustup, you need to set the environment flag
69-
`SYSROOT` during installation so Clippy knows where to find `librustc` and
70-
similar crates.
67+
#### Step 3: Install clippy
68+
69+
Once you have rustup and the nightly toolchain installed, run the following command:
7170

7271
```terminal
73-
SYSROOT=/path/to/rustc/sysroot cargo install clippy
72+
rustup component add clippy-preview --toolchain=nightly
7473
```
7574

75+
Now you can run Clippy by invoking `cargo +nightly clippy`. If nightly is your
76+
default toolchain in rustup, `cargo clippy` will work fine.
77+
7678
### Running Clippy from the command line without installing it
7779

7880
To have cargo compile your crate with Clippy without Clippy installation

ci/base-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cargo test --features debugging
66
mkdir -p ~/rust/cargo/bin
77
cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy
88
cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver
9+
rm ~/.cargo/bin/cargo-clippy
910
PATH=$PATH:~/rust/cargo/bin cargo clippy --all -- -D clippy
1011
cd clippy_workspace_tests && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy && cd ..
1112
cd clippy_workspace_tests/src && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy && cd ../..

ci/integration-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set -x
2+
rm ~/.cargo/bin/cargo-clippy
23
cargo install --force --path .
34

45
echo "Running integration test for crate ${INTEGRATION}"

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl LintPass for Pass {
6363

6464
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6565
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
66-
if let ExprLit(ref lit) = e.node {
66+
if let ExprKind::Lit(ref lit) = e.node {
6767
check_lit(cx, lit, e);
6868
}
6969
}

clippy_lints/src/arithmetic.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
5555
return;
5656
}
5757
match expr.node {
58-
hir::ExprBinary(ref op, ref l, ref r) => {
58+
hir::ExprKind::Binary(ref op, ref l, ref r) => {
5959
match op.node {
60-
hir::BiAnd
61-
| hir::BiOr
62-
| hir::BiBitAnd
63-
| hir::BiBitOr
64-
| hir::BiBitXor
65-
| hir::BiShl
66-
| hir::BiShr
67-
| hir::BiEq
68-
| hir::BiLt
69-
| hir::BiLe
70-
| hir::BiNe
71-
| hir::BiGe
72-
| hir::BiGt => return,
60+
hir::BinOpKind::And
61+
| hir::BinOpKind::Or
62+
| hir::BinOpKind::BitAnd
63+
| hir::BinOpKind::BitOr
64+
| hir::BinOpKind::BitXor
65+
| hir::BinOpKind::Shl
66+
| hir::BinOpKind::Shr
67+
| hir::BinOpKind::Eq
68+
| hir::BinOpKind::Lt
69+
| hir::BinOpKind::Le
70+
| hir::BinOpKind::Ne
71+
| hir::BinOpKind::Ge
72+
| hir::BinOpKind::Gt => return,
7373
_ => (),
7474
}
7575
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));
@@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
8181
self.span = Some(expr.span);
8282
}
8383
},
84-
hir::ExprUnary(hir::UnOp::UnNeg, ref arg) => {
84+
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
8585
let ty = cx.tables.expr_ty(arg);
8686
if ty.is_integral() {
8787
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");

clippy_lints/src/assign_ops.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LintPass for AssignOps {
7676
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7777
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
7878
match expr.node {
79-
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
79+
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
8080
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
8181
let lhs = &sugg::Sugg::hir(cx, lhs, "..");
8282
let rhs = &sugg::Sugg::hir(cx, rhs, "..");
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8787
format!("{} = {}", lhs, sugg::make_binop(higher::binop(op.node), lhs, rhs)),
8888
);
8989
});
90-
if let hir::ExprBinary(binop, ref l, ref r) = rhs.node {
90+
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
9191
if op.node == binop.node {
9292
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
9393
span_lint_and_then(
@@ -131,8 +131,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
131131
}
132132
}
133133
},
134-
hir::ExprAssign(ref assignee, ref e) => {
135-
if let hir::ExprBinary(op, ref l, ref r) = e.node {
134+
hir::ExprKind::Assign(ref assignee, ref e) => {
135+
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
136136
#[allow(cyclomatic_complexity)]
137137
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
138138
let ty = cx.tables.expr_ty(assignee);
@@ -142,9 +142,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
142142
$cx:expr,
143143
$ty:expr,
144144
$rty:expr,
145-
$($trait_name:ident:$full_trait_name:ident),+) => {
145+
$($trait_name:ident),+) => {
146146
match $op {
147-
$(hir::$full_trait_name => {
147+
$(hir::BinOpKind::$trait_name => {
148148
let [krate, module] = crate::utils::paths::OPS_MODULE;
149149
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
150150
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
@@ -159,7 +159,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
159159
if_chain! {
160160
if parent_impl != ast::CRATE_NODE_ID;
161161
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
162-
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) =
162+
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
163163
item.node;
164164
if trait_ref.path.def.def_id() == trait_id;
165165
then { return; }
@@ -175,18 +175,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
175175
cx,
176176
ty,
177177
rty.into(),
178-
Add: BiAdd,
179-
Sub: BiSub,
180-
Mul: BiMul,
181-
Div: BiDiv,
182-
Rem: BiRem,
183-
And: BiAnd,
184-
Or: BiOr,
185-
BitAnd: BiBitAnd,
186-
BitOr: BiBitOr,
187-
BitXor: BiBitXor,
188-
Shr: BiShr,
189-
Shl: BiShl
178+
Add,
179+
Sub,
180+
Mul,
181+
Div,
182+
Rem,
183+
And,
184+
Or,
185+
BitAnd,
186+
BitOr,
187+
BitXor,
188+
Shr,
189+
Shl
190190
) {
191191
span_lint_and_then(
192192
cx,
@@ -224,13 +224,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
224224
// a = b commutative_op a
225225
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
226226
match op.node {
227-
hir::BiAdd
228-
| hir::BiMul
229-
| hir::BiAnd
230-
| hir::BiOr
231-
| hir::BiBitXor
232-
| hir::BiBitAnd
233-
| hir::BiBitOr => {
227+
hir::BinOpKind::Add
228+
| hir::BinOpKind::Mul
229+
| hir::BinOpKind::And
230+
| hir::BinOpKind::Or
231+
| hir::BinOpKind::BitXor
232+
| hir::BinOpKind::BitAnd
233+
| hir::BinOpKind::BitOr => {
234234
lint(assignee, l);
235235
},
236236
_ => {},
@@ -244,11 +244,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
244244
}
245245
}
246246

247-
fn is_commutative(op: hir::BinOp_) -> bool {
248-
use rustc::hir::BinOp_::*;
247+
fn is_commutative(op: hir::BinOpKind) -> bool {
248+
use rustc::hir::BinOpKind::*;
249249
match op {
250-
BiAdd | BiMul | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr | BiEq | BiNe => true,
251-
BiSub | BiDiv | BiRem | BiShl | BiShr | BiLt | BiLe | BiGe | BiGt => false,
250+
Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
251+
Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,
252252
}
253253
}
254254

clippy_lints/src/attrs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
154154
check_attrs(cx, item.span, item.name, &item.attrs)
155155
}
156156
match item.node {
157-
ItemExternCrate(_) | ItemUse(_, _) => {
157+
ItemKind::ExternCrate(_) | ItemKind::Use(_, _) => {
158158
for attr in &item.attrs {
159159
if let Some(ref lint_list) = attr.meta_item_list() {
160160
match &*attr.name().as_str() {
161161
"allow" | "warn" | "deny" | "forbid" => {
162162
// whitelist `unused_imports` and `deprecated`
163163
for lint in lint_list {
164164
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
165-
if let ItemUse(_, _) = item.node {
165+
if let ItemKind::Use(_, _) = item.node {
166166
return;
167167
}
168168
}
@@ -207,7 +207,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
207207
}
208208

209209
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
210-
if let ItemFn(_, _, _, eid) = item.node {
210+
if let ItemKind::Fn(_, _, _, eid) = item.node {
211211
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
212212
} else {
213213
true
@@ -234,8 +234,8 @@ fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
234234
fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
235235
if let Some(stmt) = block.stmts.first() {
236236
match stmt.node {
237-
StmtDecl(_, _) => true,
238-
StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
237+
StmtKind::Decl(_, _) => true,
238+
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
239239
}
240240
} else {
241241
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
@@ -244,10 +244,10 @@ fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> b
244244

245245
fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
246246
match expr.node {
247-
ExprBlock(ref block, _) => is_relevant_block(tcx, tables, block),
248-
ExprRet(Some(ref e)) => is_relevant_expr(tcx, tables, e),
249-
ExprRet(None) | ExprBreak(_, None) => false,
250-
ExprCall(ref path_expr, _) => if let ExprPath(ref qpath) = path_expr.node {
247+
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
248+
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
249+
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
250+
ExprKind::Call(ref path_expr, _) => if let ExprKind::Path(ref qpath) = path_expr.node {
251251
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
252252
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
253253
} else {

0 commit comments

Comments
 (0)