Skip to content

Commit 8a2b6d9

Browse files
committed
Update clippy
1 parent 4c2181b commit 8a2b6d9

Some content is hidden

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

58 files changed

+1834
-506
lines changed

.travis.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ os:
99

1010
sudo: false
1111

12+
branches:
13+
# Don't build these branches
14+
except:
15+
# Used by bors
16+
- trying.tmp
17+
- staging.tmp
18+
1219
env:
1320
global:
1421
- RUST_BACKTRACE=1
@@ -56,7 +63,8 @@ matrix:
5663
- env: INTEGRATION=chronotope/chrono
5764
- env: INTEGRATION=serde-rs/serde
5865
- env: INTEGRATION=Geal/nom
59-
- env: INTEGRATION=hyperium/hyper
66+
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
67+
# - env: INTEGRATION=hyperium/hyper
6068
allow_failures:
6169
- os: windows
6270
env: BASE_TEST=true
@@ -67,13 +75,14 @@ matrix:
6775
- os: windows
6876

6977
script:
70-
- |
71-
rm rust-toolchain
72-
cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
73-
RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
74-
travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH
75-
rustup default master
76-
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
78+
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
79+
# - |
80+
# rm rust-toolchain
81+
# cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
82+
# RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
83+
# travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH
84+
# rustup default master
85+
# export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
7786
- |
7887
if [ -z ${INTEGRATION} ]; then
7988
./ci/base-tests.sh && sleep 5

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ All notable changes to this project will be documented in this file.
744744
[`match_same_arms`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#match_same_arms
745745
[`match_wild_err_arm`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#match_wild_err_arm
746746
[`maybe_infinite_iter`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#maybe_infinite_iter
747+
[`mem_discriminant_non_enum`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum
747748
[`mem_forget`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mem_forget
748749
[`mem_replace_option_with_none`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#mem_replace_option_with_none
749750
[`min_max`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#min_max
@@ -812,6 +813,7 @@ All notable changes to this project will be documented in this file.
812813
[`range_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_plus_one
813814
[`range_step_by_zero`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_step_by_zero
814815
[`range_zip_with_len`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_zip_with_len
816+
[`redundant_clone`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_clone
815817
[`redundant_closure`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_closure
816818
[`redundant_closure_call`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_closure_call
817819
[`redundant_field_names`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_field_names
@@ -893,6 +895,7 @@ All notable changes to this project will be documented in this file.
893895
[`while_immutable_condition`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_immutable_condition
894896
[`while_let_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_loop
895897
[`while_let_on_iterator`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_on_iterator
898+
[`wildcard_dependencies`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#wildcard_dependencies
896899
[`write_literal`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_literal
897900
[`write_with_newline`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_with_newline
898901
[`writeln_empty_string`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#writeln_empty_string

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rustc_tools_util = { version = "0.1.0", path = "rustc_tools_util"}
4848
[dev-dependencies]
4949
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
5050
cargo_metadata = "0.6"
51-
compiletest_rs = "0.3.7"
51+
compiletest_rs = "0.3.16"
5252
lazy_static = "1.0"
5353
serde_derive = "1.0"
5454
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in
99

1010
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
1111

12-
[There are 280 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
12+
[There are 283 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
1313

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

appveyor.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@ environment:
77
#- TARGET: x86_64-pc-windows-gnu
88
- TARGET: x86_64-pc-windows-msvc
99

10+
branches:
11+
# Don't build these branches
12+
except:
13+
# Used by bors
14+
- trying.tmp
15+
- staging.tmp
16+
1017
install:
1118
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
1219
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly
1320
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
1421
- git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt
1522
- set /p RUSTC_HASH=<rustc-hash.txt
16-
- del rust-toolchain
17-
- cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
18-
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
19-
- rustup default master
20-
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
23+
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
24+
# - del rust-toolchain
25+
# - cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
26+
# - rustup-toolchain-install-master %RUSTC_HASH% -f -n master
27+
# - rustup default master
28+
# - set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2129
- rustc -V
2230
- cargo -V
2331

bors.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
"continuous-integration/appveyor/branch"
4+
]

ci/base-tests.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ cd clippy_lints && cargo test && cd ..
2424
cd rustc_tools_util && cargo test && cd ..
2525
# check that the lint lists are up-to-date
2626
./util/update_lints.py -c
27-
mkdir -p ~/rust/cargo/bin
28-
cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy
29-
cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver
30-
rm ~/.cargo/bin/cargo-clippy
27+
28+
CLIPPY="`pwd`/target/debug/cargo-clippy clippy"
3129
# run clippy on its own codebase...
32-
PATH=$PATH:~/rust/cargo/bin cargo clippy --all-targets --all-features -- -D clippy::all -D clippy::internal
30+
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal
3331
# ... and some test directories
34-
cd clippy_workspace_tests && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ..
35-
cd clippy_workspace_tests/src && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ../..
36-
cd clippy_workspace_tests/subcrate && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ../..
37-
cd clippy_workspace_tests/subcrate/src && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ../../..
38-
cd clippy_dev && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ..
39-
cd rustc_tools_util/ && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ..
32+
for dir in clippy_workspace_tests clippy_workspace_tests/src clippy_workspace_tests/subcrate clippy_workspace_tests/subcrate/src clippy_dev rustc_tools_util
33+
do
34+
cd ${dir}
35+
${CLIPPY} -- -D clippy::all
36+
cd -
37+
done
38+
4039

4140
# test --manifest-path
42-
PATH=$PATH:~/rust/cargo/bin cargo clippy --manifest-path=clippy_workspace_tests/Cargo.toml -- -D clippy::all
43-
cd clippy_workspace_tests/subcrate && PATH=$PATH:~/rust/cargo/bin cargo clippy --manifest-path=../Cargo.toml -- -D clippy::all && cd ../..
41+
${CLIPPY} --manifest-path=clippy_workspace_tests/Cargo.toml -- -D clippy::all
42+
cd clippy_workspace_tests/subcrate && ${CLIPPY} --manifest-path=../Cargo.toml -- -D clippy::all && cd ../..
4443
set +x

ci/integration-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ function check() {
2828
}
2929

3030
case ${INTEGRATION} in
31-
rust-lang/cargo)
32-
check
33-
;;
3431
*)
3532
check
3633
;;

clippy_lints/src/arithmetic.rs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ declare_clippy_lint! {
5151

5252
#[derive(Copy, Clone, Default)]
5353
pub struct Arithmetic {
54-
span: Option<Span>,
54+
expr_span: Option<Span>,
55+
/// This field is used to check whether expressions are constants, such as in enum discriminants and consts
56+
const_span: Option<Span>,
5557
}
5658

5759
impl LintPass for Arithmetic {
@@ -62,9 +64,15 @@ impl LintPass for Arithmetic {
6264

6365
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
6466
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
65-
if self.span.is_some() {
67+
if self.expr_span.is_some() {
6668
return;
6769
}
70+
71+
if let Some(span) = self.const_span {
72+
if span.contains(expr.span) {
73+
return;
74+
}
75+
}
6876
match expr.node {
6977
hir::ExprKind::Binary(ref op, ref l, ref r) => {
7078
match op.node {
@@ -86,29 +94,60 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
8694
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));
8795
if l_ty.is_integral() && r_ty.is_integral() {
8896
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
89-
self.span = Some(expr.span);
97+
self.expr_span = Some(expr.span);
9098
} else if l_ty.is_floating_point() && r_ty.is_floating_point() {
9199
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
92-
self.span = Some(expr.span);
100+
self.expr_span = Some(expr.span);
93101
}
94102
},
95103
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
96104
let ty = cx.tables.expr_ty(arg);
97105
if ty.is_integral() {
98106
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
99-
self.span = Some(expr.span);
107+
self.expr_span = Some(expr.span);
100108
} else if ty.is_floating_point() {
101109
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
102-
self.span = Some(expr.span);
110+
self.expr_span = Some(expr.span);
103111
}
104112
},
105113
_ => (),
106114
}
107115
}
108116

109117
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
110-
if Some(expr.span) == self.span {
111-
self.span = None;
118+
if Some(expr.span) == self.expr_span {
119+
self.expr_span = None;
120+
}
121+
}
122+
123+
fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body) {
124+
let body_owner = cx.tcx.hir.body_owner(body.id());
125+
126+
match cx.tcx.hir.body_owner_kind(body_owner) {
127+
hir::BodyOwnerKind::Static(_)
128+
| hir::BodyOwnerKind::Const => {
129+
let body_span = cx.tcx.hir.span(body_owner);
130+
131+
if let Some(span) = self.const_span {
132+
if span.contains(body_span) {
133+
return;
134+
}
135+
}
136+
self.const_span = Some(body_span);
137+
}
138+
hir::BodyOwnerKind::Fn => (),
139+
}
140+
}
141+
142+
fn check_body_post(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body) {
143+
let body_owner = cx.tcx.hir.body_owner(body.id());
144+
let body_span = cx.tcx.hir.span(body_owner);
145+
146+
if let Some(span) = self.const_span {
147+
if span.contains(body_span) {
148+
return;
149+
}
112150
}
151+
self.const_span = None;
113152
}
114153
}

clippy_lints/src/identity_conversion.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1212
use crate::rustc::{declare_tool_lint, lint_array};
1313
use crate::rustc::hir::*;
1414
use crate::syntax::ast::NodeId;
15-
use crate::utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, span_lint_and_then};
15+
use crate::utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then};
1616
use crate::utils::{opt_def_id, paths, resolve_node};
1717
use crate::rustc_errors::Applicability;
1818

@@ -72,7 +72,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
7272
let a = cx.tables.expr_ty(e);
7373
let b = cx.tables.expr_ty(&args[0]);
7474
if same_tys(cx, a, b) {
75-
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
75+
let sugg = snippet_with_macro_callsite(cx, args[0].span, "<expr>").to_string();
76+
7677
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
7778
db.span_suggestion_with_applicability(
7879
e.span,

0 commit comments

Comments
 (0)