You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -40,15 +40,26 @@ error: casting `f32` to `i32` may truncate the value
40
40
--> $DIR/cast.rs:24:5
41
41
|
42
42
LL | 1f32 as i32;
43
-
| ^^^^^^^^^^^ help: avoid silent truncation by using: `i32::try_from(1f32).expect("truncation should be impossible because...")`
43
+
| ^^^^^^^^^^^
44
44
|
45
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
45
46
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
47
+
help: ... or use `try_from` and handle the error accordingly
48
+
|
49
+
LL | i32::try_from(1f32);
50
+
| ~~~~~~~~~~~~~~~~~~~
46
51
47
52
error: casting `f32` to `u32` may truncate the value
48
53
--> $DIR/cast.rs:25:5
49
54
|
50
55
LL | 1f32 as u32;
51
-
| ^^^^^^^^^^^ help: avoid silent truncation by using: `u32::try_from(1f32).expect("truncation should be impossible because...")`
56
+
| ^^^^^^^^^^^
57
+
|
58
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
59
+
help: ... or use `try_from` and handle the error accordingly
60
+
|
61
+
LL | u32::try_from(1f32);
62
+
| ~~~~~~~~~~~~~~~~~~~
52
63
53
64
error: casting `f32` to `u32` may lose the sign of the value
54
65
--> $DIR/cast.rs:25:5
@@ -62,31 +73,61 @@ error: casting `f64` to `f32` may truncate the value
62
73
--> $DIR/cast.rs:26:5
63
74
|
64
75
LL | 1f64 as f32;
65
-
| ^^^^^^^^^^^ help: avoid silent truncation by using: `f32::try_from(1f64).expect("truncation should be impossible because...")`
76
+
| ^^^^^^^^^^^
77
+
|
78
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
79
+
help: ... or use `try_from` and handle the error accordingly
80
+
|
81
+
LL | f32::try_from(1f64);
82
+
| ~~~~~~~~~~~~~~~~~~~
66
83
67
84
error: casting `i32` to `i8` may truncate the value
68
85
--> $DIR/cast.rs:27:5
69
86
|
70
87
LL | 1i32 as i8;
71
-
| ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(1i32).expect("truncation should be impossible because...")`
88
+
| ^^^^^^^^^^
89
+
|
90
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
91
+
help: ... or use `try_from` and handle the error accordingly
92
+
|
93
+
LL | i8::try_from(1i32);
94
+
| ~~~~~~~~~~~~~~~~~~
72
95
73
96
error: casting `i32` to `u8` may truncate the value
74
97
--> $DIR/cast.rs:28:5
75
98
|
76
99
LL | 1i32 as u8;
77
-
| ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(1i32).expect("truncation should be impossible because...")`
100
+
| ^^^^^^^^^^
101
+
|
102
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
103
+
help: ... or use `try_from` and handle the error accordingly
104
+
|
105
+
LL | u8::try_from(1i32);
106
+
| ~~~~~~~~~~~~~~~~~~
78
107
79
108
error: casting `f64` to `isize` may truncate the value
80
109
--> $DIR/cast.rs:29:5
81
110
|
82
111
LL | 1f64 as isize;
83
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `isize::try_from(1f64).expect("truncation should be impossible because...")`
112
+
| ^^^^^^^^^^^^^
113
+
|
114
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
115
+
help: ... or use `try_from` and handle the error accordingly
116
+
|
117
+
LL | isize::try_from(1f64);
118
+
| ~~~~~~~~~~~~~~~~~~~~~
84
119
85
120
error: casting `f64` to `usize` may truncate the value
86
121
--> $DIR/cast.rs:30:5
87
122
|
88
123
LL | 1f64 as usize;
89
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(1f64).expect("truncation should be impossible because...")`
124
+
| ^^^^^^^^^^^^^
125
+
|
126
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
127
+
help: ... or use `try_from` and handle the error accordingly
128
+
|
129
+
LL | usize::try_from(1f64);
130
+
| ~~~~~~~~~~~~~~~~~~~~~
90
131
91
132
error: casting `f64` to `usize` may lose the sign of the value
92
133
--> $DIR/cast.rs:30:5
@@ -142,19 +183,37 @@ error: casting `i64` to `i8` may truncate the value
142
183
--> $DIR/cast.rs:108:5
143
184
|
144
185
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
145
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from((-99999999999i64).min(1)).expect("truncation should be impossible because...")`
186
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
187
+
|
188
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
189
+
help: ... or use `try_from` and handle the error accordingly
190
+
|
191
+
LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed
192
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
193
147
194
error: casting `u64` to `u8` may truncate the value
148
195
--> $DIR/cast.rs:120:5
149
196
|
150
197
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
151
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(999999u64.clamp(0, 256)).expect("truncation should be impossible because...")`
198
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
199
+
|
200
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
201
+
help: ... or use `try_from` and handle the error accordingly
202
+
|
203
+
LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
204
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152
205
153
206
error: casting `main::E2` to `u8` may truncate the value
154
207
--> $DIR/cast.rs:141:21
155
208
|
156
209
LL | let _ = self as u8;
157
-
| ^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from(self).expect("truncation should be impossible because...")`
210
+
| ^^^^^^^^^^
211
+
|
212
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
213
+
help: ... or use `try_from` and handle the error accordingly
214
+
|
215
+
LL | let _ = u8::try_from(self);
216
+
| ~~~~~~~~~~~~~~~~~~
158
217
159
218
error: casting `main::E2::B` to `u8` will truncate the value
160
219
--> $DIR/cast.rs:142:21
@@ -168,7 +227,13 @@ error: casting `main::E5` to `i8` may truncate the value
168
227
--> $DIR/cast.rs:178:21
169
228
|
170
229
LL | let _ = self as i8;
171
-
| ^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(self).expect("truncation should be impossible because...")`
230
+
| ^^^^^^^^^^
231
+
|
232
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
233
+
help: ... or use `try_from` and handle the error accordingly
234
+
|
235
+
LL | let _ = i8::try_from(self);
236
+
| ~~~~~~~~~~~~~~~~~~
172
237
173
238
error: casting `main::E5::A` to `i8` will truncate the value
174
239
--> $DIR/cast.rs:179:21
@@ -180,31 +245,61 @@ error: casting `main::E6` to `i16` may truncate the value
180
245
--> $DIR/cast.rs:193:21
181
246
|
182
247
LL | let _ = self as i16;
183
-
| ^^^^^^^^^^^ help: avoid silent truncation by using: `i16::try_from(self).expect("truncation should be impossible because...")`
248
+
| ^^^^^^^^^^^
249
+
|
250
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
251
+
help: ... or use `try_from` and handle the error accordingly
252
+
|
253
+
LL | let _ = i16::try_from(self);
254
+
| ~~~~~~~~~~~~~~~~~~~
184
255
185
256
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
186
257
--> $DIR/cast.rs:208:21
187
258
|
188
259
LL | let _ = self as usize;
189
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(self).expect("truncation should be impossible because...")`
260
+
| ^^^^^^^^^^^^^
261
+
|
262
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
263
+
help: ... or use `try_from` and handle the error accordingly
264
+
|
265
+
LL | let _ = usize::try_from(self);
266
+
| ~~~~~~~~~~~~~~~~~~~~~
190
267
191
268
error: casting `main::E10` to `u16` may truncate the value
192
269
--> $DIR/cast.rs:249:21
193
270
|
194
271
LL | let _ = self as u16;
195
-
| ^^^^^^^^^^^ help: avoid silent truncation by using: `u16::try_from(self).expect("truncation should be impossible because...")`
272
+
| ^^^^^^^^^^^
273
+
|
274
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
275
+
help: ... or use `try_from` and handle the error accordingly
276
+
|
277
+
LL | let _ = u16::try_from(self);
278
+
| ~~~~~~~~~~~~~~~~~~~
196
279
197
280
error: casting `u32` to `u8` may truncate the value
198
281
--> $DIR/cast.rs:257:13
199
282
|
200
283
LL | let c = (q >> 16) as u8;
201
-
| ^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q >> 16)).expect("truncation should be impossible because...")`
284
+
| ^^^^^^^^^^^^^^^
285
+
|
286
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
287
+
help: ... or use `try_from` and handle the error accordingly
288
+
|
289
+
LL | let c = u8::try_from((q >> 16));
290
+
| ~~~~~~~~~~~~~~~~~~~~~~~
202
291
203
292
error: casting `u32` to `u8` may truncate the value
204
293
--> $DIR/cast.rs:260:13
205
294
|
206
295
LL | let c = (q / 1000) as u8;
207
-
| ^^^^^^^^^^^^^^^^ help: avoid silent truncation by using: `u8::try_from((q / 1000)).expect("truncation should be impossible because...")`
296
+
| ^^^^^^^^^^^^^^^^
297
+
|
298
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
299
+
help: ... or use `try_from` and handle the error accordingly
Copy file name to clipboardExpand all lines: tests/ui/cast_size.stderr
+62-9Lines changed: 62 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,14 @@ error: casting `isize` to `i8` may truncate the value
2
2
--> $DIR/cast_size.rs:12:5
3
3
|
4
4
LL | 1isize as i8;
5
-
| ^^^^^^^^^^^^ help: avoid silent truncation by using: `i8::try_from(1isize).expect("truncation should be impossible because...")`
5
+
| ^^^^^^^^^^^^
6
6
|
7
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
7
8
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
9
+
help: ... or use `try_from` and handle the error accordingly
10
+
|
11
+
LL | i8::try_from(1isize);
12
+
| ~~~~~~~~~~~~~~~~~~~~
8
13
9
14
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
15
--> $DIR/cast_size.rs:15:5
@@ -36,25 +41,49 @@ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wi
36
41
--> $DIR/cast_size.rs:19:5
37
42
|
38
43
LL | 1isize as i32;
39
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `i32::try_from(1isize).expect("truncation should be impossible because...")`
44
+
| ^^^^^^^^^^^^^
45
+
|
46
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
47
+
help: ... or use `try_from` and handle the error accordingly
48
+
|
49
+
LL | i32::try_from(1isize);
50
+
| ~~~~~~~~~~~~~~~~~~~~~
40
51
41
52
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
42
53
--> $DIR/cast_size.rs:20:5
43
54
|
44
55
LL | 1isize as u32;
45
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `u32::try_from(1isize).expect("truncation should be impossible because...")`
56
+
| ^^^^^^^^^^^^^
57
+
|
58
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
59
+
help: ... or use `try_from` and handle the error accordingly
60
+
|
61
+
LL | u32::try_from(1isize);
62
+
| ~~~~~~~~~~~~~~~~~~~~~
46
63
47
64
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
48
65
--> $DIR/cast_size.rs:21:5
49
66
|
50
67
LL | 1usize as u32;
51
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `u32::try_from(1usize).expect("truncation should be impossible because...")`
68
+
| ^^^^^^^^^^^^^
69
+
|
70
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
71
+
help: ... or use `try_from` and handle the error accordingly
72
+
|
73
+
LL | u32::try_from(1usize);
74
+
| ~~~~~~~~~~~~~~~~~~~~~
52
75
53
76
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
54
77
--> $DIR/cast_size.rs:22:5
55
78
|
56
79
LL | 1usize as i32;
57
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `i32::try_from(1usize).expect("truncation should be impossible because...")`
80
+
| ^^^^^^^^^^^^^
81
+
|
82
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
83
+
help: ... or use `try_from` and handle the error accordingly
84
+
|
85
+
LL | i32::try_from(1usize);
86
+
| ~~~~~~~~~~~~~~~~~~~~~
58
87
59
88
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
60
89
--> $DIR/cast_size.rs:22:5
@@ -68,19 +97,37 @@ error: casting `i64` to `isize` may truncate the value on targets with 32-bit wi
68
97
--> $DIR/cast_size.rs:24:5
69
98
|
70
99
LL | 1i64 as isize;
71
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `isize::try_from(1i64).expect("truncation should be impossible because...")`
100
+
| ^^^^^^^^^^^^^
101
+
|
102
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
103
+
help: ... or use `try_from` and handle the error accordingly
104
+
|
105
+
LL | isize::try_from(1i64);
106
+
| ~~~~~~~~~~~~~~~~~~~~~
72
107
73
108
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
74
109
--> $DIR/cast_size.rs:25:5
75
110
|
76
111
LL | 1i64 as usize;
77
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(1i64).expect("truncation should be impossible because...")`
112
+
| ^^^^^^^^^^^^^
113
+
|
114
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
115
+
help: ... or use `try_from` and handle the error accordingly
116
+
|
117
+
LL | usize::try_from(1i64);
118
+
| ~~~~~~~~~~~~~~~~~~~~~
78
119
79
120
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
80
121
--> $DIR/cast_size.rs:26:5
81
122
|
82
123
LL | 1u64 as isize;
83
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `isize::try_from(1u64).expect("truncation should be impossible because...")`
124
+
| ^^^^^^^^^^^^^
125
+
|
126
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
127
+
help: ... or use `try_from` and handle the error accordingly
128
+
|
129
+
LL | isize::try_from(1u64);
130
+
| ~~~~~~~~~~~~~~~~~~~~~
84
131
85
132
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
86
133
--> $DIR/cast_size.rs:26:5
@@ -92,7 +139,13 @@ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wi
92
139
--> $DIR/cast_size.rs:27:5
93
140
|
94
141
LL | 1u64 as usize;
95
-
| ^^^^^^^^^^^^^ help: avoid silent truncation by using: `usize::try_from(1u64).expect("truncation should be impossible because...")`
142
+
| ^^^^^^^^^^^^^
143
+
|
144
+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
145
+
help: ... or use `try_from` and handle the error accordingly
146
+
|
147
+
LL | usize::try_from(1u64);
148
+
| ~~~~~~~~~~~~~~~~~~~~~
96
149
97
150
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
0 commit comments