Skip to content

Commit fcc60cf

Browse files
committed
Use reference conversions from noisy_float
1 parent 8c9409a commit fcc60cf

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ rand = "0.5"
1313
quickcheck = "0.7"
1414

1515
[patch.crates-io]
16-
noisy_float = { git = "https://github.com/SergiusIW/noisy_float-rs.git", rev = "de01a40ceb1443110fe0b53f93c5164934e5c126" }
16+
noisy_float = { git = "https://github.com/SergiusIW/noisy_float-rs.git", rev = "c33a94803987475bbd205c9ff5a697af533f9a17" }

src/maybe_nan/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@ macro_rules! impl_maybenan_for_fxx {
7979
}
8080

8181
fn try_as_not_nan(&self) -> Option<&$Nxx> {
82-
if self.is_nan() {
83-
None
84-
} else {
85-
// This is safe because `$Nxx` is a thin `repr(C)` wrapper
86-
// around `$fxx`, and we have just checked that `self` is
87-
// not a NaN value.
88-
Some(unsafe { &*(self as *const $fxx as *const $Nxx) })
89-
}
82+
$Nxx::try_borrowed(self)
9083
}
9184

9285
fn from_not_nan(value: $Nxx) -> $fxx {
@@ -103,9 +96,7 @@ macro_rules! impl_maybenan_for_fxx {
10396
fn from_not_nan_ref_opt(value: Option<&$Nxx>) -> &$fxx {
10497
match value {
10598
None => &::std::$fxx::NAN,
106-
// This is safe because `$Nxx` is a thin `repr(C)` wrapper
107-
// around `$fxx`.
108-
Some(num) => unsafe { &*(num as *const $Nxx as *const $fxx) },
99+
Some(num) => num.as_ref(),
109100
}
110101
}
111102

0 commit comments

Comments
 (0)