Skip to content

Commit 7a245c6

Browse files
Better handle 32bit/64bit-specific ui tests
1 parent 8ae4e7f commit 7a245c6

6 files changed

+89
-77
lines changed

tests/ui/cast_size.64bit.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: casting `isize` to `i8` may truncate the value
2-
--> tests/ui/cast_size.rs:15:5
2+
--> tests/ui/cast_size.rs:17:5
33
|
44
LL | 1isize as i8;
55
| ^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL | i8::try_from(1isize);
1313
| ~~~~~~~~~~~~~~~~~~~~
1414

1515
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)
16-
--> tests/ui/cast_size.rs:22:5
16+
--> tests/ui/cast_size.rs:24:5
1717
|
1818
LL | x0 as f32;
1919
| ^^^^^^^^^
@@ -22,25 +22,25 @@ LL | x0 as f32;
2222
= help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]`
2323

2424
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)
25-
--> tests/ui/cast_size.rs:24:5
25+
--> tests/ui/cast_size.rs:26:5
2626
|
2727
LL | x1 as f32;
2828
| ^^^^^^^^^
2929

3030
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)
31-
--> tests/ui/cast_size.rs:26:5
31+
--> tests/ui/cast_size.rs:28:5
3232
|
3333
LL | x0 as f64;
3434
| ^^^^^^^^^
3535

3636
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)
37-
--> tests/ui/cast_size.rs:28:5
37+
--> tests/ui/cast_size.rs:30:5
3838
|
3939
LL | x1 as f64;
4040
| ^^^^^^^^^
4141

4242
error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers
43-
--> tests/ui/cast_size.rs:33:5
43+
--> tests/ui/cast_size.rs:35:5
4444
|
4545
LL | 1isize as i32;
4646
| ^^^^^^^^^^^^^
@@ -52,7 +52,7 @@ LL | i32::try_from(1isize);
5252
| ~~~~~~~~~~~~~~~~~~~~~
5353

5454
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
55-
--> tests/ui/cast_size.rs:35:5
55+
--> tests/ui/cast_size.rs:37:5
5656
|
5757
LL | 1isize as u32;
5858
| ^^^^^^^^^^^^^
@@ -64,7 +64,7 @@ LL | u32::try_from(1isize);
6464
| ~~~~~~~~~~~~~~~~~~~~~
6565

6666
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
67-
--> tests/ui/cast_size.rs:37:5
67+
--> tests/ui/cast_size.rs:39:5
6868
|
6969
LL | 1usize as u32;
7070
| ^^^^^^^^^^^^^
@@ -76,7 +76,7 @@ LL | u32::try_from(1usize);
7676
| ~~~~~~~~~~~~~~~~~~~~~
7777

7878
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
79-
--> tests/ui/cast_size.rs:39:5
79+
--> tests/ui/cast_size.rs:41:5
8080
|
8181
LL | 1usize as i32;
8282
| ^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | i32::try_from(1usize);
8888
| ~~~~~~~~~~~~~~~~~~~~~
8989

9090
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
91-
--> tests/ui/cast_size.rs:39:5
91+
--> tests/ui/cast_size.rs:41:5
9292
|
9393
LL | 1usize as i32;
9494
| ^^^^^^^^^^^^^
@@ -97,7 +97,7 @@ LL | 1usize as i32;
9797
= help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]`
9898

9999
error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers
100-
--> tests/ui/cast_size.rs:42:5
100+
--> tests/ui/cast_size.rs:44:5
101101
|
102102
LL | 1i64 as isize;
103103
| ^^^^^^^^^^^^^
@@ -109,7 +109,7 @@ LL | isize::try_from(1i64);
109109
| ~~~~~~~~~~~~~~~~~~~~~
110110

111111
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
112-
--> tests/ui/cast_size.rs:44:5
112+
--> tests/ui/cast_size.rs:46:5
113113
|
114114
LL | 1i64 as usize;
115115
| ^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | usize::try_from(1i64);
121121
| ~~~~~~~~~~~~~~~~~~~~~
122122

123123
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
124-
--> tests/ui/cast_size.rs:46:5
124+
--> tests/ui/cast_size.rs:48:5
125125
|
126126
LL | 1u64 as isize;
127127
| ^^^^^^^^^^^^^
@@ -133,13 +133,13 @@ LL | isize::try_from(1u64);
133133
| ~~~~~~~~~~~~~~~~~~~~~
134134

135135
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
136-
--> tests/ui/cast_size.rs:46:5
136+
--> tests/ui/cast_size.rs:48:5
137137
|
138138
LL | 1u64 as isize;
139139
| ^^^^^^^^^^^^^
140140

141141
error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
142-
--> tests/ui/cast_size.rs:49:5
142+
--> tests/ui/cast_size.rs:51:5
143143
|
144144
LL | 1u64 as usize;
145145
| ^^^^^^^^^^^^^
@@ -151,19 +151,19 @@ LL | usize::try_from(1u64);
151151
| ~~~~~~~~~~~~~~~~~~~~~
152152

153153
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
154-
--> tests/ui/cast_size.rs:51:5
154+
--> tests/ui/cast_size.rs:53:5
155155
|
156156
LL | 1u32 as isize;
157157
| ^^^^^^^^^^^^^
158158

159159
error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
160-
--> tests/ui/cast_size.rs:59:5
160+
--> tests/ui/cast_size.rs:61:5
161161
|
162162
LL | 999_999_999 as f32;
163163
| ^^^^^^^^^^^^^^^^^^
164164

165165
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)
166-
--> tests/ui/cast_size.rs:61:5
166+
--> tests/ui/cast_size.rs:63:5
167167
|
168168
LL | 9_999_999_999_999_999usize as f64;
169169
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/cast_size.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//@stderr-per-bitwidth
1+
//@revisions: 32bit 64bit
2+
//@[32bit]ignore-bitwidth: 64
3+
//@[64bit]ignore-bitwidth: 32
24
//@no-rustfix
35

46
#![warn(
@@ -60,5 +62,6 @@ fn main() {
6062
//~^ cast_precision_loss
6163
9_999_999_999_999_999usize as f64;
6264
//~^ cast_precision_loss
65+
//~[32bit]^^ overflowing_literals
6366
// 999_999_999_999_999_999_999_999_999_999u128 as f128;
6467
}

tests/ui/fn_to_numeric_cast.64bit.stderr

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: casting function pointer `foo` to `i8`, which truncates the value
2-
--> tests/ui/fn_to_numeric_cast.rs:10:13
2+
--> tests/ui/fn_to_numeric_cast.rs:12:13
33
|
44
LL | let _ = foo as i8;
55
| ^^^^^^^^^ help: try: `foo as usize`
@@ -8,19 +8,19 @@ LL | let _ = foo as i8;
88
= help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]`
99

1010
error: casting function pointer `foo` to `i16`, which truncates the value
11-
--> tests/ui/fn_to_numeric_cast.rs:12:13
11+
--> tests/ui/fn_to_numeric_cast.rs:14:13
1212
|
1313
LL | let _ = foo as i16;
1414
| ^^^^^^^^^^ help: try: `foo as usize`
1515

1616
error: casting function pointer `foo` to `i32`, which truncates the value
17-
--> tests/ui/fn_to_numeric_cast.rs:14:13
17+
--> tests/ui/fn_to_numeric_cast.rs:16:13
1818
|
1919
LL | let _ = foo as i32;
2020
| ^^^^^^^^^^ help: try: `foo as usize`
2121

2222
error: casting function pointer `foo` to `i64`
23-
--> tests/ui/fn_to_numeric_cast.rs:16:13
23+
--> tests/ui/fn_to_numeric_cast.rs:19:13
2424
|
2525
LL | let _ = foo as i64;
2626
| ^^^^^^^^^^ help: try: `foo as usize`
@@ -29,115 +29,115 @@ LL | let _ = foo as i64;
2929
= help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]`
3030

3131
error: casting function pointer `foo` to `i128`
32-
--> tests/ui/fn_to_numeric_cast.rs:18:13
32+
--> tests/ui/fn_to_numeric_cast.rs:21:13
3333
|
3434
LL | let _ = foo as i128;
3535
| ^^^^^^^^^^^ help: try: `foo as usize`
3636

3737
error: casting function pointer `foo` to `isize`
38-
--> tests/ui/fn_to_numeric_cast.rs:20:13
38+
--> tests/ui/fn_to_numeric_cast.rs:23:13
3939
|
4040
LL | let _ = foo as isize;
4141
| ^^^^^^^^^^^^ help: try: `foo as usize`
4242

4343
error: casting function pointer `foo` to `u8`, which truncates the value
44-
--> tests/ui/fn_to_numeric_cast.rs:23:13
44+
--> tests/ui/fn_to_numeric_cast.rs:26:13
4545
|
4646
LL | let _ = foo as u8;
4747
| ^^^^^^^^^ help: try: `foo as usize`
4848

4949
error: casting function pointer `foo` to `u16`, which truncates the value
50-
--> tests/ui/fn_to_numeric_cast.rs:25:13
50+
--> tests/ui/fn_to_numeric_cast.rs:28:13
5151
|
5252
LL | let _ = foo as u16;
5353
| ^^^^^^^^^^ help: try: `foo as usize`
5454

5555
error: casting function pointer `foo` to `u32`, which truncates the value
56-
--> tests/ui/fn_to_numeric_cast.rs:27:13
56+
--> tests/ui/fn_to_numeric_cast.rs:30:13
5757
|
5858
LL | let _ = foo as u32;
5959
| ^^^^^^^^^^ help: try: `foo as usize`
6060

6161
error: casting function pointer `foo` to `u64`
62-
--> tests/ui/fn_to_numeric_cast.rs:29:13
62+
--> tests/ui/fn_to_numeric_cast.rs:33:13
6363
|
6464
LL | let _ = foo as u64;
6565
| ^^^^^^^^^^ help: try: `foo as usize`
6666

6767
error: casting function pointer `foo` to `u128`
68-
--> tests/ui/fn_to_numeric_cast.rs:31:13
68+
--> tests/ui/fn_to_numeric_cast.rs:35:13
6969
|
7070
LL | let _ = foo as u128;
7171
| ^^^^^^^^^^^ help: try: `foo as usize`
7272

7373
error: casting function pointer `abc` to `i8`, which truncates the value
74-
--> tests/ui/fn_to_numeric_cast.rs:45:13
74+
--> tests/ui/fn_to_numeric_cast.rs:49:13
7575
|
7676
LL | let _ = abc as i8;
7777
| ^^^^^^^^^ help: try: `abc as usize`
7878

7979
error: casting function pointer `abc` to `i16`, which truncates the value
80-
--> tests/ui/fn_to_numeric_cast.rs:47:13
80+
--> tests/ui/fn_to_numeric_cast.rs:51:13
8181
|
8282
LL | let _ = abc as i16;
8383
| ^^^^^^^^^^ help: try: `abc as usize`
8484

8585
error: casting function pointer `abc` to `i32`, which truncates the value
86-
--> tests/ui/fn_to_numeric_cast.rs:49:13
86+
--> tests/ui/fn_to_numeric_cast.rs:53:13
8787
|
8888
LL | let _ = abc as i32;
8989
| ^^^^^^^^^^ help: try: `abc as usize`
9090

9191
error: casting function pointer `abc` to `i64`
92-
--> tests/ui/fn_to_numeric_cast.rs:51:13
92+
--> tests/ui/fn_to_numeric_cast.rs:56:13
9393
|
9494
LL | let _ = abc as i64;
9595
| ^^^^^^^^^^ help: try: `abc as usize`
9696

9797
error: casting function pointer `abc` to `i128`
98-
--> tests/ui/fn_to_numeric_cast.rs:53:13
98+
--> tests/ui/fn_to_numeric_cast.rs:58:13
9999
|
100100
LL | let _ = abc as i128;
101101
| ^^^^^^^^^^^ help: try: `abc as usize`
102102

103103
error: casting function pointer `abc` to `isize`
104-
--> tests/ui/fn_to_numeric_cast.rs:55:13
104+
--> tests/ui/fn_to_numeric_cast.rs:60:13
105105
|
106106
LL | let _ = abc as isize;
107107
| ^^^^^^^^^^^^ help: try: `abc as usize`
108108

109109
error: casting function pointer `abc` to `u8`, which truncates the value
110-
--> tests/ui/fn_to_numeric_cast.rs:58:13
110+
--> tests/ui/fn_to_numeric_cast.rs:63:13
111111
|
112112
LL | let _ = abc as u8;
113113
| ^^^^^^^^^ help: try: `abc as usize`
114114

115115
error: casting function pointer `abc` to `u16`, which truncates the value
116-
--> tests/ui/fn_to_numeric_cast.rs:60:13
116+
--> tests/ui/fn_to_numeric_cast.rs:65:13
117117
|
118118
LL | let _ = abc as u16;
119119
| ^^^^^^^^^^ help: try: `abc as usize`
120120

121121
error: casting function pointer `abc` to `u32`, which truncates the value
122-
--> tests/ui/fn_to_numeric_cast.rs:62:13
122+
--> tests/ui/fn_to_numeric_cast.rs:67:13
123123
|
124124
LL | let _ = abc as u32;
125125
| ^^^^^^^^^^ help: try: `abc as usize`
126126

127127
error: casting function pointer `abc` to `u64`
128-
--> tests/ui/fn_to_numeric_cast.rs:64:13
128+
--> tests/ui/fn_to_numeric_cast.rs:70:13
129129
|
130130
LL | let _ = abc as u64;
131131
| ^^^^^^^^^^ help: try: `abc as usize`
132132

133133
error: casting function pointer `abc` to `u128`
134-
--> tests/ui/fn_to_numeric_cast.rs:66:13
134+
--> tests/ui/fn_to_numeric_cast.rs:72:13
135135
|
136136
LL | let _ = abc as u128;
137137
| ^^^^^^^^^^^ help: try: `abc as usize`
138138

139139
error: casting function pointer `f` to `i32`, which truncates the value
140-
--> tests/ui/fn_to_numeric_cast.rs:74:5
140+
--> tests/ui/fn_to_numeric_cast.rs:80:5
141141
|
142142
LL | f as i32
143143
| ^^^^^^^^ help: try: `f as usize`

tests/ui/fn_to_numeric_cast.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//@stderr-per-bitwidth
1+
//@revisions: 32bit 64bit
2+
//@[32bit]ignore-bitwidth: 64
3+
//@[64bit]ignore-bitwidth: 32
24
//@no-rustfix
35
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
46

@@ -12,7 +14,8 @@ fn test_function_to_numeric_cast() {
1214
let _ = foo as i16;
1315
//~^ fn_to_numeric_cast_with_truncation
1416
let _ = foo as i32;
15-
//~^ fn_to_numeric_cast_with_truncation
17+
//~[64bit]^ fn_to_numeric_cast_with_truncation
18+
//~[32bit]^^ fn_to_numeric_cast
1619
let _ = foo as i64;
1720
//~^ fn_to_numeric_cast
1821
let _ = foo as i128;
@@ -25,7 +28,8 @@ fn test_function_to_numeric_cast() {
2528
let _ = foo as u16;
2629
//~^ fn_to_numeric_cast_with_truncation
2730
let _ = foo as u32;
28-
//~^ fn_to_numeric_cast_with_truncation
31+
//~[64bit]^ fn_to_numeric_cast_with_truncation
32+
//~[32bit]^^ fn_to_numeric_cast
2933
let _ = foo as u64;
3034
//~^ fn_to_numeric_cast
3135
let _ = foo as u128;
@@ -47,7 +51,8 @@ fn test_function_var_to_numeric_cast() {
4751
let _ = abc as i16;
4852
//~^ fn_to_numeric_cast_with_truncation
4953
let _ = abc as i32;
50-
//~^ fn_to_numeric_cast_with_truncation
54+
//~[64bit]^ fn_to_numeric_cast_with_truncation
55+
//~[32bit]^^ fn_to_numeric_cast
5156
let _ = abc as i64;
5257
//~^ fn_to_numeric_cast
5358
let _ = abc as i128;
@@ -60,7 +65,8 @@ fn test_function_var_to_numeric_cast() {
6065
let _ = abc as u16;
6166
//~^ fn_to_numeric_cast_with_truncation
6267
let _ = abc as u32;
63-
//~^ fn_to_numeric_cast_with_truncation
68+
//~[64bit]^ fn_to_numeric_cast_with_truncation
69+
//~[32bit]^^ fn_to_numeric_cast
6470
let _ = abc as u64;
6571
//~^ fn_to_numeric_cast
6672
let _ = abc as u128;
@@ -72,7 +78,8 @@ fn test_function_var_to_numeric_cast() {
7278

7379
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
7480
f as i32
75-
//~^ fn_to_numeric_cast_with_truncation
81+
//~[64bit]^ fn_to_numeric_cast_with_truncation
82+
//~[32bit]^^ ERROR: literal out of range for `usize`
7683
}
7784

7885
fn main() {}

0 commit comments

Comments
 (0)