diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-09 14:41:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-09 14:41:51 +0100 |
| commit | 475c47a3c14d6c09486509029e288daced2bed86 (patch) | |
| tree | 5265365ad77fb57af3872c1e6614ca3f20100b19 | |
| parent | df2281b058a0396f3e8775056f3173d3870fc7dd (diff) | |
| parent | d70d3204b7e669ff8046bfe55999a36a39896c08 (diff) | |
| download | rust-475c47a3c14d6c09486509029e288daced2bed86.tar.gz rust-475c47a3c14d6c09486509029e288daced2bed86.zip | |
Rollup merge of #120809 - reitermarkus:generic-nonzero-constructors, r=Nilstrieb
Use `transmute_unchecked` in `NonZero::new`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 See https://github.com/rust-lang/rust/pull/120521#discussion_r1482615129.
| -rw-r--r-- | library/core/src/num/nonzero.rs | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 193f2fa8731..bf676cb2248 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -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; @@ -91,13 +90,12 @@ where /// Creates a non-zero if the given value is not zero. #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")] - #[rustc_allow_const_fn_unstable(const_refs_to_cell)] #[must_use] #[inline] 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. |
