Skip to content

Commit 5bcff44

Browse files
committed
Update Clippy
1 parent 555ee8f commit 5bcff44

32 files changed

+206
-45
lines changed

appveyor.yml

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
environment:
2-
global:
3-
PROJECT_NAME: rust-clippy
4-
matrix:
5-
#- TARGET: i686-pc-windows-gnu
6-
#- TARGET: i686-pc-windows-msvc
7-
#- TARGET: x86_64-pc-windows-gnu
8-
- TARGET: x86_64-pc-windows-msvc
2+
global:
3+
PROJECT_NAME: rust-clippy
4+
RUST_BACKTRACE: 1
5+
matrix:
6+
#- TARGET: i686-pc-windows-gnu
7+
#- TARGET: i686-pc-windows-msvc
8+
#- TARGET: x86_64-pc-windows-gnu
9+
- TARGET: x86_64-pc-windows-msvc
910

1011
branches:
11-
# Only build AppVeyor on r+ and try branch
12-
only:
13-
- auto
14-
- try
12+
# Only build AppVeyor on r+ and try branch
13+
only:
14+
- auto
15+
- try
1516

1617
cache:
17-
- '%USERPROFILE%\.cargo'
18+
- '%USERPROFILE%\.cargo'
19+
# before cache
1820
after_test:
19-
- cargo install -Z install-upgrade cargo-cache --debug
20-
- cargo cache --autoclean
21+
- cargo install -Z install-upgrade cargo-cache --debug
22+
- cargo cache --autoclean
2123

2224
install:
23-
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
24-
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly --profile=minimal
25-
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
26-
- del rust-toolchain
27-
- cargo install -Z install-upgrade rustup-toolchain-install-master
28-
- rustup-toolchain-install-master -f -n master -c rustc-dev
29-
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
30-
- rustup default master
31-
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
32-
- rustc -V
33-
- cargo -V
25+
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
26+
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly --profile=minimal
27+
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
28+
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
29+
- del rust-toolchain
30+
- cargo install -Z install-upgrade rustup-toolchain-install-master
31+
- rustup-toolchain-install-master -f -n master -c rustc-dev
32+
- rustup override set master
33+
- rustc -V
34+
- cargo -V
3435

36+
# Build settings, not to be confused with "before_build" and "after_build".
3537
build: false
3638

39+
build_script:
40+
- cargo build --features debugging
41+
3742
test_script:
38-
- set RUST_BACKTRACE=1
39-
- cargo build --features debugging
40-
- cargo test --features debugging
43+
- cargo test --features debugging
4144

4245
notifications:
43-
- provider: Email
44-
on_build_success: false
46+
- provider: Email
47+
on_build_success: false

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
11831183
LintId::of(&misc_early::UNNEEDED_FIELD_PATTERN),
11841184
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
11851185
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
1186-
LintId::of(&mul_add::MANUAL_MUL_ADD),
11871186
LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED),
11881187
LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
11891188
LintId::of(&mutex_atomic::MUTEX_ATOMIC),
@@ -1527,7 +1526,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
15271526
LintId::of(&methods::OR_FUN_CALL),
15281527
LintId::of(&methods::SINGLE_CHAR_PATTERN),
15291528
LintId::of(&misc::CMP_OWNED),
1530-
LintId::of(&mul_add::MANUAL_MUL_ADD),
15311529
LintId::of(&mutex_atomic::MUTEX_ATOMIC),
15321530
LintId::of(&redundant_clone::REDUNDANT_CLONE),
15331531
LintId::of(&slow_vector_initialization::SLOW_VECTOR_INITIALIZATION),
@@ -1546,6 +1544,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
15461544
LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
15471545
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
15481546
LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN),
1547+
LintId::of(&mul_add::MANUAL_MUL_ADD),
15491548
LintId::of(&mutex_atomic::MUTEX_INTEGER),
15501549
LintId::of(&needless_borrow::NEEDLESS_BORROW),
15511550
LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),

clippy_lints/src/mul_add.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ declare_clippy_lint! {
1515
/// `c`. Depending on the target architecture, `mul_add()` may be more
1616
/// performant.
1717
///
18-
/// **Known problems:** None.
18+
/// **Known problems:** This lint can emit semantic incorrect suggestions.
19+
/// For example, for `a * b * c + d` the suggestion `a * b.mul_add(c, d)`
20+
/// is emitted, which is equivalent to `a * (b * c + d)`. (#4735)
1921
///
2022
/// **Example:**
2123
///
@@ -35,7 +37,7 @@ declare_clippy_lint! {
3537
/// let foo = a.mul_add(b, c);
3638
/// ```
3739
pub MANUAL_MUL_ADD,
38-
perf,
40+
nursery,
3941
"Using `a.mul_add(b, c)` for floating points has higher numerical precision than `a * b + c`"
4042
}
4143

clippy_lints/src/try_err.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{match_qpath, paths, snippet, snippet_with_macro_callsite, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc::hir::*;
4-
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4+
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass};
55
use rustc::ty::Ty;
66
use rustc::{declare_lint_pass, declare_tool_lint};
77
use rustc_errors::Applicability;
@@ -54,6 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr {
5454
// val,
5555
// };
5656
if_chain! {
57+
if !in_external_macro(cx.tcx.sess, expr.span);
5758
if let ExprKind::Match(ref match_arg, _, MatchSource::TryDesugar) = expr.kind;
5859
if let ExprKind::Call(ref match_fun, ref try_args) = match_arg.kind;
5960
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;

setup-toolchain.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,28 @@ set -e
55

66
cd "$(dirname "$0")"
77

8-
if [[ "$CI" == true ]] || ! command -v rustup-toolchain-install-master > /dev/null; then
9-
cargo install -Z install-upgrade rustup-toolchain-install-master --bin rustup-toolchain-install-master
8+
ERRNO=0
9+
RTIM_PATH=$(command -v rustup-toolchain-install-master) || ERRNO=$?
10+
CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}
11+
12+
# Check if people also install RTIM in other locations beside
13+
# ~/.cargo/bin
14+
if [[ "$ERRNO" -ne 0 ]] || [[ "$RTIM_PATH" == $CARGO_HOME/bin/rustup-toolchain-install-master ]]; then
15+
cargo install -Z install-upgrade rustup-toolchain-install-master
16+
else
17+
VERSION=$(rustup-toolchain-install-master -V | grep -o "[0-9.]*")
18+
REMOTE=$(cargo search rustup-toolchain-install-master | grep -o "[0-9.]*")
19+
echo "info: skipping updating rustup-toolchain-install-master at $RTIM_PATH"
20+
echo " current version : $VERSION"
21+
echo " remote version : $REMOTE"
22+
fi
23+
24+
RUST_COMMIT=$(git ls-remote https://github.com/rust-lang/rust master | awk '{print $1}')
25+
26+
if rustc +master -Vv 2>/dev/null | grep -q "$RUST_COMMIT"; then
27+
echo "info: master toolchain is up-to-date"
28+
exit 0
1029
fi
1130

12-
rustup-toolchain-install-master -f -n master -c rustc-dev
31+
rustup-toolchain-install-master -f -n master -c rustc-dev -- "$RUST_COMMIT"
1332
rustup override set master

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ pub const ALL_LINTS: [Lint; 332] = [
961961
},
962962
Lint {
963963
name: "manual_mul_add",
964-
group: "perf",
964+
group: "nursery",
965965
desc: "Using `a.mul_add(b, c)` for floating points has higher numerical precision than `a * b + c`",
966966
deprecation: None,
967967
module: "mul_add",

tests/ui/assign_ops2.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ error: variable appears on both sides of an assignment operation
1919
|
2020
LL | a += 1 + a;
2121
| ^^^^^^^^^^
22+
|
2223
help: Did you mean a = a + 1 or a = a + 1 + a? Consider replacing it with
2324
|
2425
LL | a += 1;
@@ -33,6 +34,7 @@ error: variable appears on both sides of an assignment operation
3334
|
3435
LL | a -= a - 1;
3536
| ^^^^^^^^^^
37+
|
3638
help: Did you mean a = a - 1 or a = a - (a - 1)? Consider replacing it with
3739
|
3840
LL | a -= 1;
@@ -47,6 +49,7 @@ error: variable appears on both sides of an assignment operation
4749
|
4850
LL | a *= a * 99;
4951
| ^^^^^^^^^^^
52+
|
5053
help: Did you mean a = a * 99 or a = a * a * 99? Consider replacing it with
5154
|
5255
LL | a *= 99;
@@ -61,6 +64,7 @@ error: variable appears on both sides of an assignment operation
6164
|
6265
LL | a *= 42 * a;
6366
| ^^^^^^^^^^^
67+
|
6468
help: Did you mean a = a * 42 or a = a * 42 * a? Consider replacing it with
6569
|
6670
LL | a *= 42;
@@ -75,6 +79,7 @@ error: variable appears on both sides of an assignment operation
7579
|
7680
LL | a /= a / 2;
7781
| ^^^^^^^^^^
82+
|
7883
help: Did you mean a = a / 2 or a = a / (a / 2)? Consider replacing it with
7984
|
8085
LL | a /= 2;
@@ -89,6 +94,7 @@ error: variable appears on both sides of an assignment operation
8994
|
9095
LL | a %= a % 5;
9196
| ^^^^^^^^^^
97+
|
9298
help: Did you mean a = a % 5 or a = a % (a % 5)? Consider replacing it with
9399
|
94100
LL | a %= 5;
@@ -103,6 +109,7 @@ error: variable appears on both sides of an assignment operation
103109
|
104110
LL | a &= a & 1;
105111
| ^^^^^^^^^^
112+
|
106113
help: Did you mean a = a & 1 or a = a & a & 1? Consider replacing it with
107114
|
108115
LL | a &= 1;
@@ -117,6 +124,7 @@ error: variable appears on both sides of an assignment operation
117124
|
118125
LL | a *= a * a;
119126
| ^^^^^^^^^^
127+
|
120128
help: Did you mean a = a * a or a = a * a * a? Consider replacing it with
121129
|
122130
LL | a *= a;

tests/ui/auxiliary/macro_rules.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ macro_rules! must_use_unit {
1616
fn foo() {}
1717
};
1818
}
19+
20+
#[macro_export]
21+
macro_rules! try_err {
22+
() => {
23+
pub fn try_err_fn() -> Result<i32, i32> {
24+
let err: i32 = 1;
25+
// To avoid warnings during rustfix
26+
if true {
27+
Err(err)?
28+
} else {
29+
Ok(2)
30+
}
31+
}
32+
};
33+
}

tests/ui/booleans.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ error: this boolean expression can be simplified
7272
|
7373
LL | let _ = a == b && c == 5 && a == b;
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
75+
|
7576
help: try
7677
|
7778
LL | let _ = a == b && c == 5;
@@ -84,6 +85,7 @@ error: this boolean expression can be simplified
8485
|
8586
LL | let _ = a == b && c == 5 && b == a;
8687
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
|
8789
help: try
8890
|
8991
LL | let _ = a == b && c == 5;
@@ -120,6 +122,7 @@ error: this boolean expression can be simplified
120122
|
121123
LL | let _ = a != b || !(a != b || c == d);
122124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
|
123126
help: try
124127
|
125128
LL | let _ = c != d || a != b;

tests/ui/collapsible_if.stderr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ LL | | println!("Hello world!");
2525
LL | | }
2626
LL | | }
2727
| |_____^
28+
|
2829
help: try
2930
|
3031
LL | if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
@@ -41,6 +42,7 @@ LL | | println!("Hello world!");
4142
LL | | }
4243
LL | | }
4344
| |_____^
45+
|
4446
help: try
4547
|
4648
LL | if x == "hello" && x == "world" && (y == "world" || y == "hello") {
@@ -57,6 +59,7 @@ LL | | println!("Hello world!");
5759
LL | | }
5860
LL | | }
5961
| |_____^
62+
|
6063
help: try
6164
|
6265
LL | if (x == "hello" || x == "world") && y == "world" && y == "hello" {
@@ -73,6 +76,7 @@ LL | | println!("Hello world!");
7376
LL | | }
7477
LL | | }
7578
| |_____^
79+
|
7680
help: try
7781
|
7882
LL | if x == "hello" && x == "world" && y == "world" && y == "hello" {
@@ -89,6 +93,7 @@ LL | | println!("world!")
8993
LL | | }
9094
LL | | }
9195
| |_____^
96+
|
9297
help: try
9398
|
9499
LL | if 42 == 1337 && 'a' != 'A' {
@@ -106,6 +111,7 @@ LL | | println!("world!")
106111
LL | | }
107112
LL | | }
108113
| |_____^
114+
|
109115
help: try
110116
|
111117
LL | } else if y == "world" {
@@ -123,6 +129,7 @@ LL | | println!("world!")
123129
LL | | }
124130
LL | | }
125131
| |_____^
132+
|
126133
help: try
127134
|
128135
LL | } else if let Some(42) = Some(42) {
@@ -142,6 +149,7 @@ LL | | }
142149
LL | | }
143150
LL | | }
144151
| |_____^
152+
|
145153
help: try
146154
|
147155
LL | } else if y == "world" {
@@ -164,6 +172,7 @@ LL | | }
164172
LL | | }
165173
LL | | }
166174
| |_____^
175+
|
167176
help: try
168177
|
169178
LL | } else if let Some(42) = Some(42) {
@@ -186,6 +195,7 @@ LL | | }
186195
LL | | }
187196
LL | | }
188197
| |_____^
198+
|
189199
help: try
190200
|
191201
LL | } else if let Some(42) = Some(42) {
@@ -208,6 +218,7 @@ LL | | }
208218
LL | | }
209219
LL | | }
210220
| |_____^
221+
|
211222
help: try
212223
|
213224
LL | } else if x == "hello" {
@@ -230,6 +241,7 @@ LL | | }
230241
LL | | }
231242
LL | | }
232243
| |_____^
244+
|
233245
help: try
234246
|
235247
LL | } else if let Some(42) = Some(42) {
@@ -249,6 +261,7 @@ LL | | println!("Hello world!");
249261
LL | | }
250262
LL | | }
251263
| |_____^
264+
|
252265
help: try
253266
|
254267
LL | if x == "hello" && y == "world" { // Collapsible

0 commit comments

Comments
 (0)