From b0224fb794f2aaa1449f02b873976c95b04eeca0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 5 Oct 2024 21:35:04 +0200 Subject: [PATCH] add missing safety comments --- library/core/src/num/f128.rs | 1 + library/core/src/num/f16.rs | 1 + library/core/src/num/f32.rs | 2 ++ library/core/src/num/f64.rs | 2 ++ 4 files changed, 6 insertions(+) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index a551ccfe9ed92..90d3035f15731 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -1378,6 +1378,7 @@ impl f128 { #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] #[must_use = "method returns a new number and does not mutate the original value"] pub const fn copysign(self, sign: f128) -> f128 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::copysignf128(self, sign) } } } diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index 0d77377af746e..85b2ad18886a5 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -1352,6 +1352,7 @@ impl f16 { #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] #[must_use = "method returns a new number and does not mutate the original value"] pub const fn copysign(self, sign: f16) -> f16 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::copysignf16(self, sign) } } } diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index d9337af316ce8..51241fa102788 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -1449,6 +1449,7 @@ impl f32 { #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] #[inline] pub const fn abs(self) -> f32 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::fabsf32(self) } } @@ -1509,6 +1510,7 @@ impl f32 { #[stable(feature = "copysign", since = "1.35.0")] #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] pub const fn copysign(self, sign: f32) -> f32 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::copysignf32(self, sign) } } } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index bcab5193718d7..f42eaf8317747 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -1449,6 +1449,7 @@ impl f64 { #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] #[inline] pub const fn abs(self) -> f64 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::fabsf64(self) } } @@ -1509,6 +1510,7 @@ impl f64 { #[rustc_const_unstable(feature = "const_float_methods", issue = "130843")] #[inline] pub const fn copysign(self, sign: f64) -> f64 { + // SAFETY: this is actually a safe intrinsic unsafe { intrinsics::copysignf64(self, sign) } } }