Skip to content

Commit 1476217

Browse files
authored
Unrolled build for #120809
Rollup merge of #120809 - reitermarkus:generic-nonzero-constructors, r=Nilstrieb Use `transmute_unchecked` in `NonZero::new`. Tracking issue: #120257 See #120521 (comment).
2 parents 8fb67fb + d70d320 commit 1476217

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

library/core/src/num/nonzero.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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;
1211
use crate::str::FromStr;
1312

1413
use super::from_str_radix;
@@ -91,13 +90,12 @@ where
9190
/// Creates a non-zero if the given value is not zero.
9291
#[stable(feature = "nonzero", since = "1.28.0")]
9392
#[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")]
94-
#[rustc_allow_const_fn_unstable(const_refs_to_cell)]
9593
#[must_use]
9694
#[inline]
9795
pub const fn new(n: T) -> Option<Self> {
9896
// SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has
9997
// the same layout and size as `T`, with `0` representing `None`.
100-
unsafe { ptr::read(ptr::addr_of!(n).cast()) }
98+
unsafe { intrinsics::transmute_unchecked(n) }
10199
}
102100

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

0 commit comments

Comments
 (0)