Skip to content

Commit 4c2ea7b

Browse files
committed
Replace transmute_copy with ptr::read.
1 parent a984702 commit 4c2ea7b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/num/nonzero.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::intrinsics;
88
use crate::marker::StructuralEq;
99
use crate::marker::StructuralPartialEq;
1010
use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem};
11+
use crate::ptr;
1112
use crate::str::FromStr;
1213

1314
use super::from_str_radix;
@@ -96,7 +97,7 @@ where
9697
pub const fn new(n: T) -> Option<Self> {
9798
// SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has
9899
// the same layout and size as `T`, with `0` representing `None`.
99-
unsafe { crate::mem::transmute_copy(&n) }
100+
unsafe { ptr::read(ptr::addr_of!(n).cast()) }
100101
}
101102

102103
/// Creates a non-zero without checking whether the value is non-zero.

0 commit comments

Comments
 (0)