From 350640598ffa8a5f2ab16eb440a01603fca3df74 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Wed, 14 Aug 2024 16:14:50 +0800 Subject: [PATCH 1/2] cleanup `NonZero::get` --- library/core/src/num/nonzero.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index c6e9c249048a7..37d331a603900 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -426,19 +426,7 @@ where #[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")] #[inline] pub const fn get(self) -> T { - // FIXME: This can be changed to simply `self.0` once LLVM supports `!range` metadata - // for function arguments: https://github.com/llvm/llvm-project/issues/76628 - // - // Rustc can set range metadata only if it loads `self` from - // memory somewhere. If the value of `self` was from by-value argument - // of some not-inlined function, LLVM don't have range metadata - // to understand that the value cannot be zero. - // - // For now, using the transmute `assume`s the range at runtime. - // - // SAFETY: `ZeroablePrimitive` guarantees that the size and bit validity - // of `.0` is such that this transmute is sound. - unsafe { intrinsics::transmute_unchecked(self) } + self.0 } } From 38b8cdbab274449cd6a691029f5de38f3814ddce Mon Sep 17 00:00:00 2001 From: Slanterns Date: Wed, 14 Aug 2024 16:53:08 +0800 Subject: [PATCH 2/2] try --- library/core/src/num/nonzero.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 37d331a603900..3f36b3de24d1f 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -426,7 +426,7 @@ where #[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")] #[inline] pub const fn get(self) -> T { - self.0 + self.0.0 } }