@@ -215,20 +215,104 @@ error: casting `usize` to `isize` may wrap around the value
215
215
LL | 1usize as isize;
216
216
| ^^^^^^^^^^^^^^^
217
217
218
- error: casting `i32` to `u32` may lose the sign of the value
218
+ error: casting `usize` to `i8` may truncate the value
219
+ --> $DIR/cast.rs:44:5
220
+ |
221
+ LL | 1usize as i8; // should not wrap, usize is never 8 bits
222
+ | ^^^^^^^^^^^^
223
+ |
224
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
225
+ help: ... or use `try_from` and handle the error accordingly
226
+ |
227
+ LL | i8::try_from(1usize); // should not wrap, usize is never 8 bits
228
+ | ~~~~~~~~~~~~~~~~~~~~
229
+
230
+ error: casting `usize` to `i16` may truncate the value
231
+ --> $DIR/cast.rs:45:5
232
+ |
233
+ LL | 1usize as i16; // wraps on 16 bit ptr size
234
+ | ^^^^^^^^^^^^^
235
+ |
236
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
237
+ help: ... or use `try_from` and handle the error accordingly
238
+ |
239
+ LL | i16::try_from(1usize); // wraps on 16 bit ptr size
240
+ | ~~~~~~~~~~~~~~~~~~~~~
241
+
242
+ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers
243
+ --> $DIR/cast.rs:45:5
244
+ |
245
+ LL | 1usize as i16; // wraps on 16 bit ptr size
246
+ | ^^^^^^^^^^^^^
247
+
248
+ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
219
249
--> $DIR/cast.rs:46:5
220
250
|
251
+ LL | 1usize as i32; // wraps on 32 bit ptr size
252
+ | ^^^^^^^^^^^^^
253
+ |
254
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
255
+ help: ... or use `try_from` and handle the error accordingly
256
+ |
257
+ LL | i32::try_from(1usize); // wraps on 32 bit ptr size
258
+ | ~~~~~~~~~~~~~~~~~~~~~
259
+
260
+ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
261
+ --> $DIR/cast.rs:46:5
262
+ |
263
+ LL | 1usize as i32; // wraps on 32 bit ptr size
264
+ | ^^^^^^^^^^^^^
265
+
266
+ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers
267
+ --> $DIR/cast.rs:47:5
268
+ |
269
+ LL | 1usize as i64; // wraps on 64 bit ptr size
270
+ | ^^^^^^^^^^^^^
271
+
272
+ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers
273
+ --> $DIR/cast.rs:49:5
274
+ |
275
+ LL | 1u16 as isize; // wraps on 16 bit ptr size
276
+ | ^^^^^^^^^^^^^
277
+
278
+ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
279
+ --> $DIR/cast.rs:50:5
280
+ |
281
+ LL | 1u32 as isize; // wraps on 32 bit ptr size
282
+ | ^^^^^^^^^^^^^
283
+
284
+ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
285
+ --> $DIR/cast.rs:51:5
286
+ |
287
+ LL | 1u64 as isize; // wraps on 64 bit ptr size
288
+ | ^^^^^^^^^^^^^
289
+ |
290
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
291
+ help: ... or use `try_from` and handle the error accordingly
292
+ |
293
+ LL | isize::try_from(1u64); // wraps on 64 bit ptr size
294
+ | ~~~~~~~~~~~~~~~~~~~~~
295
+
296
+ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
297
+ --> $DIR/cast.rs:51:5
298
+ |
299
+ LL | 1u64 as isize; // wraps on 64 bit ptr size
300
+ | ^^^^^^^^^^^^^
301
+
302
+ error: casting `i32` to `u32` may lose the sign of the value
303
+ --> $DIR/cast.rs:54:5
304
+ |
221
305
LL | -1i32 as u32;
222
306
| ^^^^^^^^^^^^
223
307
224
308
error: casting `isize` to `usize` may lose the sign of the value
225
- --> $DIR/cast.rs:48 :5
309
+ --> $DIR/cast.rs:56 :5
226
310
|
227
311
LL | -1isize as usize;
228
312
| ^^^^^^^^^^^^^^^^
229
313
230
314
error: casting `i64` to `i8` may truncate the value
231
- --> $DIR/cast.rs:115 :5
315
+ --> $DIR/cast.rs:123 :5
232
316
|
233
317
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
234
318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -240,7 +324,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
240
324
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241
325
242
326
error: casting `u64` to `u8` may truncate the value
243
- --> $DIR/cast.rs:127 :5
327
+ --> $DIR/cast.rs:135 :5
244
328
|
245
329
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
246
330
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -252,7 +336,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
252
336
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253
337
254
338
error: casting `main::E2` to `u8` may truncate the value
255
- --> $DIR/cast.rs:148 :21
339
+ --> $DIR/cast.rs:156 :21
256
340
|
257
341
LL | let _ = self as u8;
258
342
| ^^^^^^^^^^
@@ -264,15 +348,15 @@ LL | let _ = u8::try_from(self);
264
348
| ~~~~~~~~~~~~~~~~~~
265
349
266
350
error: casting `main::E2::B` to `u8` will truncate the value
267
- --> $DIR/cast.rs:149 :21
351
+ --> $DIR/cast.rs:157 :21
268
352
|
269
353
LL | let _ = Self::B as u8;
270
354
| ^^^^^^^^^^^^^
271
355
|
272
356
= note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
273
357
274
358
error: casting `main::E5` to `i8` may truncate the value
275
- --> $DIR/cast.rs:185 :21
359
+ --> $DIR/cast.rs:193 :21
276
360
|
277
361
LL | let _ = self as i8;
278
362
| ^^^^^^^^^^
@@ -284,13 +368,13 @@ LL | let _ = i8::try_from(self);
284
368
| ~~~~~~~~~~~~~~~~~~
285
369
286
370
error: casting `main::E5::A` to `i8` will truncate the value
287
- --> $DIR/cast.rs:186 :21
371
+ --> $DIR/cast.rs:194 :21
288
372
|
289
373
LL | let _ = Self::A as i8;
290
374
| ^^^^^^^^^^^^^
291
375
292
376
error: casting `main::E6` to `i16` may truncate the value
293
- --> $DIR/cast.rs:200 :21
377
+ --> $DIR/cast.rs:208 :21
294
378
|
295
379
LL | let _ = self as i16;
296
380
| ^^^^^^^^^^^
@@ -302,7 +386,7 @@ LL | let _ = i16::try_from(self);
302
386
| ~~~~~~~~~~~~~~~~~~~
303
387
304
388
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
305
- --> $DIR/cast.rs:215 :21
389
+ --> $DIR/cast.rs:223 :21
306
390
|
307
391
LL | let _ = self as usize;
308
392
| ^^^^^^^^^^^^^
@@ -314,7 +398,7 @@ LL | let _ = usize::try_from(self);
314
398
| ~~~~~~~~~~~~~~~~~~~~~
315
399
316
400
error: casting `main::E10` to `u16` may truncate the value
317
- --> $DIR/cast.rs:256 :21
401
+ --> $DIR/cast.rs:264 :21
318
402
|
319
403
LL | let _ = self as u16;
320
404
| ^^^^^^^^^^^
@@ -326,7 +410,7 @@ LL | let _ = u16::try_from(self);
326
410
| ~~~~~~~~~~~~~~~~~~~
327
411
328
412
error: casting `u32` to `u8` may truncate the value
329
- --> $DIR/cast.rs:264 :13
413
+ --> $DIR/cast.rs:272 :13
330
414
|
331
415
LL | let c = (q >> 16) as u8;
332
416
| ^^^^^^^^^^^^^^^
@@ -338,7 +422,7 @@ LL | let c = u8::try_from(q >> 16);
338
422
| ~~~~~~~~~~~~~~~~~~~~~
339
423
340
424
error: casting `u32` to `u8` may truncate the value
341
- --> $DIR/cast.rs:267 :13
425
+ --> $DIR/cast.rs:275 :13
342
426
|
343
427
LL | let c = (q / 1000) as u8;
344
428
| ^^^^^^^^^^^^^^^^
@@ -349,5 +433,5 @@ help: ... or use `try_from` and handle the error accordingly
349
433
LL | let c = u8::try_from(q / 1000);
350
434
| ~~~~~~~~~~~~~~~~~~~~~~
351
435
352
- error: aborting due to 41 previous errors
436
+ error: aborting due to 51 previous errors
353
437
0 commit comments