Skip to content

Commit 142b289

Browse files
committed
chore: fix and split some ui tests on 32bit system
1 parent 94aa039 commit 142b289

18 files changed

+482
-87
lines changed

clippy_lints/src/enum_clike.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare_clippy_lint! {
2424
///
2525
/// **Example:**
2626
/// ```rust
27+
/// # #[cfg(target_pointer_width = "64")]
2728
/// #[repr(usize)]
2829
/// enum NonPortable {
2930
/// X = 0x1_0000_0000,

tests/ui/cast_size.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-32bit
12
#[warn(
23
clippy::cast_precision_loss,
34
clippy::cast_possible_truncation,

tests/ui/cast_size.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
11
error: casting isize to i8 may truncate the value
2-
--> $DIR/cast_size.rs:11:5
2+
--> $DIR/cast_size.rs:12:5
33
|
44
LL | 1isize as i8;
55
| ^^^^^^^^^^^^
66
|
77
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
88

99
error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
10-
--> $DIR/cast_size.rs:14:5
10+
--> $DIR/cast_size.rs:15:5
1111
|
1212
LL | x0 as f64;
1313
| ^^^^^^^^^
1414
|
1515
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
1616

1717
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
18-
--> $DIR/cast_size.rs:15:5
18+
--> $DIR/cast_size.rs:16:5
1919
|
2020
LL | x1 as f64;
2121
| ^^^^^^^^^
2222

2323
error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
24-
--> $DIR/cast_size.rs:16:5
24+
--> $DIR/cast_size.rs:17:5
2525
|
2626
LL | x0 as f32;
2727
| ^^^^^^^^^
2828

2929
error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
30-
--> $DIR/cast_size.rs:17:5
30+
--> $DIR/cast_size.rs:18:5
3131
|
3232
LL | x1 as f32;
3333
| ^^^^^^^^^
3434

3535
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
36-
--> $DIR/cast_size.rs:18:5
36+
--> $DIR/cast_size.rs:19:5
3737
|
3838
LL | 1isize as i32;
3939
| ^^^^^^^^^^^^^
4040

4141
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
42-
--> $DIR/cast_size.rs:19:5
42+
--> $DIR/cast_size.rs:20:5
4343
|
4444
LL | 1isize as u32;
4545
| ^^^^^^^^^^^^^
4646

4747
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
48-
--> $DIR/cast_size.rs:20:5
48+
--> $DIR/cast_size.rs:21:5
4949
|
5050
LL | 1usize as u32;
5151
| ^^^^^^^^^^^^^
5252

5353
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
54-
--> $DIR/cast_size.rs:21:5
54+
--> $DIR/cast_size.rs:22:5
5555
|
5656
LL | 1usize as i32;
5757
| ^^^^^^^^^^^^^
5858

5959
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
60-
--> $DIR/cast_size.rs:21:5
60+
--> $DIR/cast_size.rs:22:5
6161
|
6262
LL | 1usize as i32;
6363
| ^^^^^^^^^^^^^
6464
|
6565
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
6666

6767
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
68-
--> $DIR/cast_size.rs:23:5
68+
--> $DIR/cast_size.rs:24:5
6969
|
7070
LL | 1i64 as isize;
7171
| ^^^^^^^^^^^^^
7272

7373
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
74-
--> $DIR/cast_size.rs:24:5
74+
--> $DIR/cast_size.rs:25:5
7575
|
7676
LL | 1i64 as usize;
7777
| ^^^^^^^^^^^^^
7878

7979
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
80-
--> $DIR/cast_size.rs:25:5
80+
--> $DIR/cast_size.rs:26:5
8181
|
8282
LL | 1u64 as isize;
8383
| ^^^^^^^^^^^^^
8484

8585
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
86-
--> $DIR/cast_size.rs:25:5
86+
--> $DIR/cast_size.rs:26:5
8787
|
8888
LL | 1u64 as isize;
8989
| ^^^^^^^^^^^^^
9090

9191
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
92-
--> $DIR/cast_size.rs:26:5
92+
--> $DIR/cast_size.rs:27:5
9393
|
9494
LL | 1u64 as usize;
9595
| ^^^^^^^^^^^^^
9696

9797
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
98-
--> $DIR/cast_size.rs:27:5
98+
--> $DIR/cast_size.rs:28:5
9999
|
100100
LL | 1u32 as isize;
101101
| ^^^^^^^^^^^^^
102102

103103
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
104-
--> $DIR/cast_size.rs:32:5
104+
--> $DIR/cast_size.rs:33:5
105105
|
106106
LL | 999_999_999 as f32;
107107
| ^^^^^^^^^^^^^^^^^^
108108

109109
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
110-
--> $DIR/cast_size.rs:33:5
110+
--> $DIR/cast_size.rs:34:5
111111
|
112112
LL | 9_999_999_999_999_999usize as f64;
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/cast_size_32bit.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ignore-64bit
2+
#[warn(
3+
clippy::cast_precision_loss,
4+
clippy::cast_possible_truncation,
5+
clippy::cast_sign_loss,
6+
clippy::cast_possible_wrap,
7+
clippy::cast_lossless
8+
)]
9+
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
10+
fn main() {
11+
// Casting from *size
12+
1isize as i8;
13+
let x0 = 1isize;
14+
let x1 = 1usize;
15+
x0 as f64;
16+
x1 as f64;
17+
x0 as f32;
18+
x1 as f32;
19+
1isize as i32;
20+
1isize as u32;
21+
1usize as u32;
22+
1usize as i32;
23+
// Casting to *size
24+
1i64 as isize;
25+
1i64 as usize;
26+
1u64 as isize;
27+
1u64 as usize;
28+
1u32 as isize;
29+
1u32 as usize; // Should not trigger any lint
30+
1i32 as isize; // Neither should this
31+
1i32 as usize;
32+
// Big integer literal to float
33+
999_999_999 as f32;
34+
3_999_999_999usize as f64;
35+
}

tests/ui/cast_size_32bit.stderr

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
error: casting isize to i8 may truncate the value
2+
--> $DIR/cast_size_32bit.rs:12:5
3+
|
4+
LL | 1isize as i8;
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
8+
9+
error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
10+
--> $DIR/cast_size_32bit.rs:15:5
11+
|
12+
LL | x0 as f64;
13+
| ^^^^^^^^^
14+
|
15+
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
16+
17+
error: casting isize to f64 may become silently lossy if you later change the type
18+
--> $DIR/cast_size_32bit.rs:15:5
19+
|
20+
LL | x0 as f64;
21+
| ^^^^^^^^^ help: try: `f64::from(x0)`
22+
|
23+
= note: `-D clippy::cast-lossless` implied by `-D warnings`
24+
25+
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
26+
--> $DIR/cast_size_32bit.rs:16:5
27+
|
28+
LL | x1 as f64;
29+
| ^^^^^^^^^
30+
31+
error: casting usize to f64 may become silently lossy if you later change the type
32+
--> $DIR/cast_size_32bit.rs:16:5
33+
|
34+
LL | x1 as f64;
35+
| ^^^^^^^^^ help: try: `f64::from(x1)`
36+
37+
error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
38+
--> $DIR/cast_size_32bit.rs:17:5
39+
|
40+
LL | x0 as f32;
41+
| ^^^^^^^^^
42+
43+
error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
44+
--> $DIR/cast_size_32bit.rs:18:5
45+
|
46+
LL | x1 as f32;
47+
| ^^^^^^^^^
48+
49+
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
50+
--> $DIR/cast_size_32bit.rs:19:5
51+
|
52+
LL | 1isize as i32;
53+
| ^^^^^^^^^^^^^
54+
55+
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
56+
--> $DIR/cast_size_32bit.rs:20:5
57+
|
58+
LL | 1isize as u32;
59+
| ^^^^^^^^^^^^^
60+
61+
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
62+
--> $DIR/cast_size_32bit.rs:21:5
63+
|
64+
LL | 1usize as u32;
65+
| ^^^^^^^^^^^^^
66+
67+
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
68+
--> $DIR/cast_size_32bit.rs:22:5
69+
|
70+
LL | 1usize as i32;
71+
| ^^^^^^^^^^^^^
72+
73+
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
74+
--> $DIR/cast_size_32bit.rs:22:5
75+
|
76+
LL | 1usize as i32;
77+
| ^^^^^^^^^^^^^
78+
|
79+
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
80+
81+
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
82+
--> $DIR/cast_size_32bit.rs:24:5
83+
|
84+
LL | 1i64 as isize;
85+
| ^^^^^^^^^^^^^
86+
87+
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
88+
--> $DIR/cast_size_32bit.rs:25:5
89+
|
90+
LL | 1i64 as usize;
91+
| ^^^^^^^^^^^^^
92+
93+
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
94+
--> $DIR/cast_size_32bit.rs:26:5
95+
|
96+
LL | 1u64 as isize;
97+
| ^^^^^^^^^^^^^
98+
99+
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
100+
--> $DIR/cast_size_32bit.rs:26:5
101+
|
102+
LL | 1u64 as isize;
103+
| ^^^^^^^^^^^^^
104+
105+
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
106+
--> $DIR/cast_size_32bit.rs:27:5
107+
|
108+
LL | 1u64 as usize;
109+
| ^^^^^^^^^^^^^
110+
111+
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
112+
--> $DIR/cast_size_32bit.rs:28:5
113+
|
114+
LL | 1u32 as isize;
115+
| ^^^^^^^^^^^^^
116+
117+
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
118+
--> $DIR/cast_size_32bit.rs:33:5
119+
|
120+
LL | 999_999_999 as f32;
121+
| ^^^^^^^^^^^^^^^^^^
122+
123+
error: casting integer literal to f64 is unnecessary
124+
--> $DIR/cast_size_32bit.rs:34:5
125+
|
126+
LL | 3_999_999_999usize as f64;
127+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3999999999_f64`
128+
|
129+
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
130+
131+
error: aborting due to 20 previous errors
132+

tests/ui/fn_to_numeric_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// only-64bit
1+
// ignore-32bit
22

33
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
44

tests/ui/fn_to_numeric_cast_32bit.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ignore-64bit
2+
3+
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
4+
5+
fn foo() -> String {
6+
String::new()
7+
}
8+
9+
fn test_function_to_numeric_cast() {
10+
let _ = foo as i8;
11+
let _ = foo as i16;
12+
let _ = foo as i32;
13+
let _ = foo as i64;
14+
let _ = foo as i128;
15+
let _ = foo as isize;
16+
17+
let _ = foo as u8;
18+
let _ = foo as u16;
19+
let _ = foo as u32;
20+
let _ = foo as u64;
21+
let _ = foo as u128;
22+
23+
// Casting to usize is OK and should not warn
24+
let _ = foo as usize;
25+
26+
// Cast `f` (a `FnDef`) to `fn()` should not warn
27+
fn f() {}
28+
let _ = f as fn();
29+
}
30+
31+
fn test_function_var_to_numeric_cast() {
32+
let abc: fn() -> String = foo;
33+
34+
let _ = abc as i8;
35+
let _ = abc as i16;
36+
let _ = abc as i32;
37+
let _ = abc as i64;
38+
let _ = abc as i128;
39+
let _ = abc as isize;
40+
41+
let _ = abc as u8;
42+
let _ = abc as u16;
43+
let _ = abc as u32;
44+
let _ = abc as u64;
45+
let _ = abc as u128;
46+
47+
// Casting to usize is OK and should not warn
48+
let _ = abc as usize;
49+
}
50+
51+
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
52+
f as i32
53+
}
54+
55+
fn main() {}

0 commit comments

Comments
 (0)