diff --git a/library/compiler-builtins/src/float/mod.rs b/library/compiler-builtins/src/float/mod.rs index 34b3c6ac1e88..c4b6901613fb 100644 --- a/library/compiler-builtins/src/float/mod.rs +++ b/library/compiler-builtins/src/float/mod.rs @@ -1,4 +1,3 @@ -use core::mem; use core::ops; use super::int::Int; @@ -85,8 +84,6 @@ pub trait Float: fn is_subnormal(&self) -> bool; } -// FIXME: Some of this can be removed if RFC Issue #1424 is resolved -// https://github.com/rust-lang/rfcs/issues/1424 macro_rules! float_impl { ($ty:ident, $ity:ident, $sity:ident, $bits:expr, $significand_bits:expr) => { impl Float for $ty { @@ -104,10 +101,10 @@ macro_rules! float_impl { const EXPONENT_MASK: Self::Int = !(Self::SIGN_MASK | Self::SIGNIFICAND_MASK); fn repr(self) -> Self::Int { - unsafe { mem::transmute(self) } + self.to_bits() } fn signed_repr(self) -> Self::SignedInt { - unsafe { mem::transmute(self) } + self.to_bits() as Self::SignedInt } fn eq_repr(self, rhs: Self) -> bool { if self.is_nan() && rhs.is_nan() { @@ -117,7 +114,7 @@ macro_rules! float_impl { } } fn from_repr(a: Self::Int) -> Self { - unsafe { mem::transmute(a) } + Self::from_bits(a) } fn from_parts(sign: bool, exponent: Self::Int, significand: Self::Int) -> Self { Self::from_repr( diff --git a/library/compiler-builtins/testcrate/build.rs b/library/compiler-builtins/testcrate/build.rs index 1baa6a966075..1ecd0179e885 100644 --- a/library/compiler-builtins/testcrate/build.rs +++ b/library/compiler-builtins/testcrate/build.rs @@ -633,7 +633,7 @@ fn main() { if a.0.is_nan() || b.0.is_nan() || c.is_nan() - || c.abs() <= unsafe { mem::transmute(4503599627370495u64) } + || c.abs() <= f64::from_bits(4503599627370495u64) { None } else { @@ -651,7 +651,7 @@ fn main() { if a.0.is_nan() || b.0.is_nan() || c.is_nan() - || c.abs() <= unsafe { mem::transmute(16777215u32) } + || c.abs() <= f32::from_bits(16777215u32) { None } else { @@ -671,7 +671,7 @@ fn main() { if a.0.is_nan() || b.0.is_nan() || c.is_nan() - || c.abs() <= unsafe { mem::transmute(4503599627370495u64) } + || c.abs() <= f64::from_bits(4503599627370495u64) { None } else { @@ -689,7 +689,7 @@ fn main() { if a.0.is_nan() || b.0.is_nan() || c.is_nan() - || c.abs() <= unsafe { mem::transmute(16777215u32) } + || c.abs() <= f32::from_bits(16777215u32) { None } else {