Skip to content

Commit

Permalink
Better handle 32bit/64bit-specific ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 15, 2025
1 parent 8ae4e7f commit 2c0c661
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 143 deletions.
38 changes: 19 additions & 19 deletions tests/ui/cast_size.32bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: casting `isize` to `i8` may truncate the value
--> tests/ui/cast_size.rs:15:5
--> tests/ui/cast_size.rs:17:5
|
LL | 1isize as i8;
| ^^^^^^^^^^^^
Expand All @@ -13,7 +13,7 @@ LL | i8::try_from(1isize);
| ~~~~~~~~~~~~~~~~~~~~

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

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)
--> tests/ui/cast_size.rs:24:5
--> tests/ui/cast_size.rs:26:5
|
LL | x1 as f32;
| ^^^^^^^^^

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)
--> tests/ui/cast_size.rs:26:5
--> tests/ui/cast_size.rs:28:5
|
LL | x0 as f64;
| ^^^^^^^^^

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)
--> tests/ui/cast_size.rs:28:5
--> tests/ui/cast_size.rs:30:5
|
LL | x1 as f64;
| ^^^^^^^^^

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

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

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

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

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

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

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

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

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

error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
--> tests/ui/cast_size.rs:49:5
--> tests/ui/cast_size.rs:51:5
|
LL | 1u64 as usize;
| ^^^^^^^^^^^^^
Expand All @@ -151,25 +151,25 @@ LL | usize::try_from(1u64);
| ~~~~~~~~~~~~~~~~~~~~~

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

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

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

error: literal out of range for `usize`
--> tests/ui/cast_size.rs:61:5
--> tests/ui/cast_size.rs:63:5
|
LL | 9_999_999_999_999_999usize as f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
36 changes: 18 additions & 18 deletions tests/ui/cast_size.64bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: casting `isize` to `i8` may truncate the value
--> tests/ui/cast_size.rs:15:5
--> tests/ui/cast_size.rs:17:5
|
LL | 1isize as i8;
| ^^^^^^^^^^^^
Expand All @@ -13,7 +13,7 @@ LL | i8::try_from(1isize);
| ~~~~~~~~~~~~~~~~~~~~

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

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)
--> tests/ui/cast_size.rs:24:5
--> tests/ui/cast_size.rs:26:5
|
LL | x1 as f32;
| ^^^^^^^^^

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)
--> tests/ui/cast_size.rs:26:5
--> tests/ui/cast_size.rs:28:5
|
LL | x0 as f64;
| ^^^^^^^^^

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)
--> tests/ui/cast_size.rs:28:5
--> tests/ui/cast_size.rs:30:5
|
LL | x1 as f64;
| ^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

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

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

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)
--> tests/ui/cast_size.rs:61:5
--> tests/ui/cast_size.rs:63:5
|
LL | 9_999_999_999_999_999usize as f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/cast_size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@stderr-per-bitwidth
//@revisions: 32bit 64bit
//@[32bit]ignore-bitwidth: 64
//@[64bit]ignore-bitwidth: 32
//@no-rustfix

#![warn(
Expand Down Expand Up @@ -60,5 +62,6 @@ fn main() {
//~^ cast_precision_loss
9_999_999_999_999_999usize as f64;
//~^ cast_precision_loss
//~[32bit]^^ overflowing_literals
// 999_999_999_999_999_999_999_999_999_999u128 as f128;
}
Loading

0 comments on commit 2c0c661

Please sign in to comment.