Skip to content

Commit 05467ab

Browse files
committed
Auto merge of #3626 - phansch:rustfix_works, r=oli-obk
Add run-rustfix where it already works This PR adds `// run-rustfix` headers to tests for `MachineApplicable` lints where applying the suggestions works without any errors.
2 parents d264e40 + 319f18e commit 05467ab

30 files changed

+467
-76
lines changed

tests/ui/cast_lossless_float.fixed

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
// run-rustfix
11+
12+
#[warn(clippy::cast_lossless)]
13+
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
14+
fn main() {
15+
// Test clippy::cast_lossless with casts to floating-point types
16+
f32::from(1i8);
17+
f64::from(1i8);
18+
f32::from(1u8);
19+
f64::from(1u8);
20+
f32::from(1i16);
21+
f64::from(1i16);
22+
f32::from(1u16);
23+
f64::from(1u16);
24+
f64::from(1i32);
25+
f64::from(1u32);
26+
}

tests/ui/cast_lossless_float.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
// run-rustfix
11+
1012
#[warn(clippy::cast_lossless)]
1113
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
1214
fn main() {

tests/ui/cast_lossless_float.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
error: casting i8 to f32 may become silently lossy if types change
2-
--> $DIR/cast_lossless_float.rs:14:5
2+
--> $DIR/cast_lossless_float.rs:16:5
33
|
44
LL | 1i8 as f32;
55
| ^^^^^^^^^^ help: try: `f32::from(1i8)`
66
|
77
= note: `-D clippy::cast-lossless` implied by `-D warnings`
88

99
error: casting i8 to f64 may become silently lossy if types change
10-
--> $DIR/cast_lossless_float.rs:15:5
10+
--> $DIR/cast_lossless_float.rs:17:5
1111
|
1212
LL | 1i8 as f64;
1313
| ^^^^^^^^^^ help: try: `f64::from(1i8)`
1414

1515
error: casting u8 to f32 may become silently lossy if types change
16-
--> $DIR/cast_lossless_float.rs:16:5
16+
--> $DIR/cast_lossless_float.rs:18:5
1717
|
1818
LL | 1u8 as f32;
1919
| ^^^^^^^^^^ help: try: `f32::from(1u8)`
2020

2121
error: casting u8 to f64 may become silently lossy if types change
22-
--> $DIR/cast_lossless_float.rs:17:5
22+
--> $DIR/cast_lossless_float.rs:19:5
2323
|
2424
LL | 1u8 as f64;
2525
| ^^^^^^^^^^ help: try: `f64::from(1u8)`
2626

2727
error: casting i16 to f32 may become silently lossy if types change
28-
--> $DIR/cast_lossless_float.rs:18:5
28+
--> $DIR/cast_lossless_float.rs:20:5
2929
|
3030
LL | 1i16 as f32;
3131
| ^^^^^^^^^^^ help: try: `f32::from(1i16)`
3232

3333
error: casting i16 to f64 may become silently lossy if types change
34-
--> $DIR/cast_lossless_float.rs:19:5
34+
--> $DIR/cast_lossless_float.rs:21:5
3535
|
3636
LL | 1i16 as f64;
3737
| ^^^^^^^^^^^ help: try: `f64::from(1i16)`
3838

3939
error: casting u16 to f32 may become silently lossy if types change
40-
--> $DIR/cast_lossless_float.rs:20:5
40+
--> $DIR/cast_lossless_float.rs:22:5
4141
|
4242
LL | 1u16 as f32;
4343
| ^^^^^^^^^^^ help: try: `f32::from(1u16)`
4444

4545
error: casting u16 to f64 may become silently lossy if types change
46-
--> $DIR/cast_lossless_float.rs:21:5
46+
--> $DIR/cast_lossless_float.rs:23:5
4747
|
4848
LL | 1u16 as f64;
4949
| ^^^^^^^^^^^ help: try: `f64::from(1u16)`
5050

5151
error: casting i32 to f64 may become silently lossy if types change
52-
--> $DIR/cast_lossless_float.rs:22:5
52+
--> $DIR/cast_lossless_float.rs:24:5
5353
|
5454
LL | 1i32 as f64;
5555
| ^^^^^^^^^^^ help: try: `f64::from(1i32)`
5656

5757
error: casting u32 to f64 may become silently lossy if types change
58-
--> $DIR/cast_lossless_float.rs:23:5
58+
--> $DIR/cast_lossless_float.rs:25:5
5959
|
6060
LL | 1u32 as f64;
6161
| ^^^^^^^^^^^ help: try: `f64::from(1u32)`

tests/ui/cast_lossless_integer.fixed

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
// run-rustfix
11+
12+
#[warn(clippy::cast_lossless)]
13+
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
14+
fn main() {
15+
// Test clippy::cast_lossless with casts to integer types
16+
i16::from(1i8);
17+
i32::from(1i8);
18+
i64::from(1i8);
19+
i16::from(1u8);
20+
i32::from(1u8);
21+
i64::from(1u8);
22+
u16::from(1u8);
23+
u32::from(1u8);
24+
u64::from(1u8);
25+
i32::from(1i16);
26+
i64::from(1i16);
27+
i32::from(1u16);
28+
i64::from(1u16);
29+
u32::from(1u16);
30+
u64::from(1u16);
31+
i64::from(1i32);
32+
i64::from(1u32);
33+
u64::from(1u32);
34+
}

tests/ui/cast_lossless_integer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
// run-rustfix
11+
1012
#[warn(clippy::cast_lossless)]
1113
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
1214
fn main() {

tests/ui/cast_lossless_integer.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,109 @@
11
error: casting i8 to i16 may become silently lossy if types change
2-
--> $DIR/cast_lossless_integer.rs:14:5
2+
--> $DIR/cast_lossless_integer.rs:16:5
33
|
44
LL | 1i8 as i16;
55
| ^^^^^^^^^^ help: try: `i16::from(1i8)`
66
|
77
= note: `-D clippy::cast-lossless` implied by `-D warnings`
88

99
error: casting i8 to i32 may become silently lossy if types change
10-
--> $DIR/cast_lossless_integer.rs:15:5
10+
--> $DIR/cast_lossless_integer.rs:17:5
1111
|
1212
LL | 1i8 as i32;
1313
| ^^^^^^^^^^ help: try: `i32::from(1i8)`
1414

1515
error: casting i8 to i64 may become silently lossy if types change
16-
--> $DIR/cast_lossless_integer.rs:16:5
16+
--> $DIR/cast_lossless_integer.rs:18:5
1717
|
1818
LL | 1i8 as i64;
1919
| ^^^^^^^^^^ help: try: `i64::from(1i8)`
2020

2121
error: casting u8 to i16 may become silently lossy if types change
22-
--> $DIR/cast_lossless_integer.rs:17:5
22+
--> $DIR/cast_lossless_integer.rs:19:5
2323
|
2424
LL | 1u8 as i16;
2525
| ^^^^^^^^^^ help: try: `i16::from(1u8)`
2626

2727
error: casting u8 to i32 may become silently lossy if types change
28-
--> $DIR/cast_lossless_integer.rs:18:5
28+
--> $DIR/cast_lossless_integer.rs:20:5
2929
|
3030
LL | 1u8 as i32;
3131
| ^^^^^^^^^^ help: try: `i32::from(1u8)`
3232

3333
error: casting u8 to i64 may become silently lossy if types change
34-
--> $DIR/cast_lossless_integer.rs:19:5
34+
--> $DIR/cast_lossless_integer.rs:21:5
3535
|
3636
LL | 1u8 as i64;
3737
| ^^^^^^^^^^ help: try: `i64::from(1u8)`
3838

3939
error: casting u8 to u16 may become silently lossy if types change
40-
--> $DIR/cast_lossless_integer.rs:20:5
40+
--> $DIR/cast_lossless_integer.rs:22:5
4141
|
4242
LL | 1u8 as u16;
4343
| ^^^^^^^^^^ help: try: `u16::from(1u8)`
4444

4545
error: casting u8 to u32 may become silently lossy if types change
46-
--> $DIR/cast_lossless_integer.rs:21:5
46+
--> $DIR/cast_lossless_integer.rs:23:5
4747
|
4848
LL | 1u8 as u32;
4949
| ^^^^^^^^^^ help: try: `u32::from(1u8)`
5050

5151
error: casting u8 to u64 may become silently lossy if types change
52-
--> $DIR/cast_lossless_integer.rs:22:5
52+
--> $DIR/cast_lossless_integer.rs:24:5
5353
|
5454
LL | 1u8 as u64;
5555
| ^^^^^^^^^^ help: try: `u64::from(1u8)`
5656

5757
error: casting i16 to i32 may become silently lossy if types change
58-
--> $DIR/cast_lossless_integer.rs:23:5
58+
--> $DIR/cast_lossless_integer.rs:25:5
5959
|
6060
LL | 1i16 as i32;
6161
| ^^^^^^^^^^^ help: try: `i32::from(1i16)`
6262

6363
error: casting i16 to i64 may become silently lossy if types change
64-
--> $DIR/cast_lossless_integer.rs:24:5
64+
--> $DIR/cast_lossless_integer.rs:26:5
6565
|
6666
LL | 1i16 as i64;
6767
| ^^^^^^^^^^^ help: try: `i64::from(1i16)`
6868

6969
error: casting u16 to i32 may become silently lossy if types change
70-
--> $DIR/cast_lossless_integer.rs:25:5
70+
--> $DIR/cast_lossless_integer.rs:27:5
7171
|
7272
LL | 1u16 as i32;
7373
| ^^^^^^^^^^^ help: try: `i32::from(1u16)`
7474

7575
error: casting u16 to i64 may become silently lossy if types change
76-
--> $DIR/cast_lossless_integer.rs:26:5
76+
--> $DIR/cast_lossless_integer.rs:28:5
7777
|
7878
LL | 1u16 as i64;
7979
| ^^^^^^^^^^^ help: try: `i64::from(1u16)`
8080

8181
error: casting u16 to u32 may become silently lossy if types change
82-
--> $DIR/cast_lossless_integer.rs:27:5
82+
--> $DIR/cast_lossless_integer.rs:29:5
8383
|
8484
LL | 1u16 as u32;
8585
| ^^^^^^^^^^^ help: try: `u32::from(1u16)`
8686

8787
error: casting u16 to u64 may become silently lossy if types change
88-
--> $DIR/cast_lossless_integer.rs:28:5
88+
--> $DIR/cast_lossless_integer.rs:30:5
8989
|
9090
LL | 1u16 as u64;
9191
| ^^^^^^^^^^^ help: try: `u64::from(1u16)`
9292

9393
error: casting i32 to i64 may become silently lossy if types change
94-
--> $DIR/cast_lossless_integer.rs:29:5
94+
--> $DIR/cast_lossless_integer.rs:31:5
9595
|
9696
LL | 1i32 as i64;
9797
| ^^^^^^^^^^^ help: try: `i64::from(1i32)`
9898

9999
error: casting u32 to i64 may become silently lossy if types change
100-
--> $DIR/cast_lossless_integer.rs:30:5
100+
--> $DIR/cast_lossless_integer.rs:32:5
101101
|
102102
LL | 1u32 as i64;
103103
| ^^^^^^^^^^^ help: try: `i64::from(1u32)`
104104

105105
error: casting u32 to u64 may become silently lossy if types change
106-
--> $DIR/cast_lossless_integer.rs:31:5
106+
--> $DIR/cast_lossless_integer.rs:33:5
107107
|
108108
LL | 1u32 as u64;
109109
| ^^^^^^^^^^^ help: try: `u64::from(1u32)`

tests/ui/double_comparison.fixed

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
// run-rustfix
11+
12+
fn main() {
13+
let x = 1;
14+
let y = 2;
15+
if x <= y {
16+
// do something
17+
}
18+
if x <= y {
19+
// do something
20+
}
21+
if x >= y {
22+
// do something
23+
}
24+
if x >= y {
25+
// do something
26+
}
27+
if x != y {
28+
// do something
29+
}
30+
if x != y {
31+
// do something
32+
}
33+
if x == y {
34+
// do something
35+
}
36+
if x == y {
37+
// do something
38+
}
39+
}

tests/ui/double_comparison.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
// run-rustfix
11+
1012
fn main() {
1113
let x = 1;
1214
let y = 2;

tests/ui/double_comparison.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: This binary expression can be simplified
2-
--> $DIR/double_comparison.rs:13:8
2+
--> $DIR/double_comparison.rs:15:8
33
|
44
LL | if x == y || x < y {
55
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
66
|
77
= note: `-D clippy::double-comparisons` implied by `-D warnings`
88

99
error: This binary expression can be simplified
10-
--> $DIR/double_comparison.rs:16:8
10+
--> $DIR/double_comparison.rs:18:8
1111
|
1212
LL | if x < y || x == y {
1313
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
1414

1515
error: This binary expression can be simplified
16-
--> $DIR/double_comparison.rs:19:8
16+
--> $DIR/double_comparison.rs:21:8
1717
|
1818
LL | if x == y || x > y {
1919
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
2020

2121
error: This binary expression can be simplified
22-
--> $DIR/double_comparison.rs:22:8
22+
--> $DIR/double_comparison.rs:24:8
2323
|
2424
LL | if x > y || x == y {
2525
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
2626

2727
error: This binary expression can be simplified
28-
--> $DIR/double_comparison.rs:25:8
28+
--> $DIR/double_comparison.rs:27:8
2929
|
3030
LL | if x < y || x > y {
3131
| ^^^^^^^^^^^^^^ help: try: `x != y`
3232

3333
error: This binary expression can be simplified
34-
--> $DIR/double_comparison.rs:28:8
34+
--> $DIR/double_comparison.rs:30:8
3535
|
3636
LL | if x > y || x < y {
3737
| ^^^^^^^^^^^^^^ help: try: `x != y`
3838

3939
error: This binary expression can be simplified
40-
--> $DIR/double_comparison.rs:31:8
40+
--> $DIR/double_comparison.rs:33:8
4141
|
4242
LL | if x <= y && x >= y {
4343
| ^^^^^^^^^^^^^^^^ help: try: `x == y`
4444

4545
error: This binary expression can be simplified
46-
--> $DIR/double_comparison.rs:34:8
46+
--> $DIR/double_comparison.rs:36:8
4747
|
4848
LL | if x >= y && x <= y {
4949
| ^^^^^^^^^^^^^^^^ help: try: `x == y`

0 commit comments

Comments
 (0)