diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/transmute_float_to_int.fixed')
-rw-r--r-- | src/tools/clippy/tests/ui/transmute_float_to_int.fixed | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/transmute_float_to_int.fixed b/src/tools/clippy/tests/ui/transmute_float_to_int.fixed new file mode 100644 index 000000000..cef0bcfa6 --- /dev/null +++ b/src/tools/clippy/tests/ui/transmute_float_to_int.fixed @@ -0,0 +1,32 @@ +#![warn(clippy::transmute_float_to_int)] + +fn float_to_int() { + let _: u32 = unsafe { 1f32.to_bits() }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` + let _: i32 = unsafe { 1f32.to_bits() as i32 }; + //~^ ERROR: transmute from a `f32` to a `i32` + let _: u64 = unsafe { 1f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` + let _: i64 = unsafe { 1f64.to_bits() as i64 }; + //~^ ERROR: transmute from a `f64` to a `i64` + let _: u64 = unsafe { 1.0f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` + let _: u64 = unsafe { (-1.0f64).to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` +} + +mod issue_5747 { + const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; + const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; + + const fn to_bits_32(v: f32) -> u32 { + unsafe { std::mem::transmute(v) } + } + + const fn to_bits_64(v: f64) -> i64 { + unsafe { std::mem::transmute(v) } + } +} + +fn main() {} |