Skip to content

Commit

Permalink
Use transmute_unchecked in NonZero::new.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 8, 2024
1 parent c29082f commit 8c613db
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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 @@ -97,7 +96,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 { ptr::read(ptr::addr_of!(n).cast()) }
unsafe { intrinsics::transmute_unchecked(n) }
}

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

0 comments on commit 8c613db

Please sign in to comment.