Skip to content

Commit f7c78b9

Browse files
committed
replace some transmutes
1 parent 0fcf89e commit f7c78b9

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/float/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use core::mem;
21
use core::ops;
32

43
use super::int::Int;
@@ -85,8 +84,6 @@ pub trait Float:
8584
fn is_subnormal(&self) -> bool;
8685
}
8786

88-
// FIXME: Some of this can be removed if RFC Issue #1424 is resolved
89-
// https://github.com/rust-lang/rfcs/issues/1424
9087
macro_rules! float_impl {
9188
($ty:ident, $ity:ident, $sity:ident, $bits:expr, $significand_bits:expr) => {
9289
impl Float for $ty {
@@ -104,10 +101,10 @@ macro_rules! float_impl {
104101
const EXPONENT_MASK: Self::Int = !(Self::SIGN_MASK | Self::SIGNIFICAND_MASK);
105102

106103
fn repr(self) -> Self::Int {
107-
unsafe { mem::transmute(self) }
104+
self.to_bits()
108105
}
109106
fn signed_repr(self) -> Self::SignedInt {
110-
unsafe { mem::transmute(self) }
107+
self.to_bits() as Self::SignedInt
111108
}
112109
fn eq_repr(self, rhs: Self) -> bool {
113110
if self.is_nan() && rhs.is_nan() {
@@ -117,7 +114,7 @@ macro_rules! float_impl {
117114
}
118115
}
119116
fn from_repr(a: Self::Int) -> Self {
120-
unsafe { mem::transmute(a) }
117+
Self::from_bits(a)
121118
}
122119
fn from_parts(sign: bool, exponent: Self::Int, significand: Self::Int) -> Self {
123120
Self::from_repr(

testcrate/build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ fn main() {
633633
if a.0.is_nan()
634634
|| b.0.is_nan()
635635
|| c.is_nan()
636-
|| c.abs() <= unsafe { mem::transmute(4503599627370495u64) }
636+
|| c.abs() <= f64::from_bits(4503599627370495u64)
637637
{
638638
None
639639
} else {
@@ -651,7 +651,7 @@ fn main() {
651651
if a.0.is_nan()
652652
|| b.0.is_nan()
653653
|| c.is_nan()
654-
|| c.abs() <= unsafe { mem::transmute(16777215u32) }
654+
|| c.abs() <= f32::from_bits(16777215u32)
655655
{
656656
None
657657
} else {
@@ -671,7 +671,7 @@ fn main() {
671671
if a.0.is_nan()
672672
|| b.0.is_nan()
673673
|| c.is_nan()
674-
|| c.abs() <= unsafe { mem::transmute(4503599627370495u64) }
674+
|| c.abs() <= f64::from_bits(4503599627370495u64)
675675
{
676676
None
677677
} else {
@@ -689,7 +689,7 @@ fn main() {
689689
if a.0.is_nan()
690690
|| b.0.is_nan()
691691
|| c.is_nan()
692-
|| c.abs() <= unsafe { mem::transmute(16777215u32) }
692+
|| c.abs() <= f32::from_bits(16777215u32)
693693
{
694694
None
695695
} else {

0 commit comments

Comments
 (0)