Skip to content

Commit

Permalink
Replace transmute_copy with ptr::read.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 7, 2024
1 parent af48cf6 commit 5d65418
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::intrinsics;
use crate::marker::StructuralEq;
use crate::marker::StructuralPartialEq;
use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem};
use crate::ptr;
use crate::str::FromStr;

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

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

0 comments on commit 5d65418

Please sign in to comment.