From 607021cb1d20d401f39f46c580dce89493c8f4af Mon Sep 17 00:00:00 2001 From: Artem Ismagilov Date: Wed, 8 Apr 2026 11:10:56 +0400 Subject: [PATCH] add must_use macros add msg --- library/core/src/num/f128.rs | 5 +++++ library/core/src/num/f16.rs | 5 +++++ library/core/src/num/f32.rs | 5 +++++ library/core/src/num/f64.rs | 5 +++++ library/std/src/num/f128.rs | 1 + library/std/src/num/f16.rs | 1 + library/std/src/num/f32.rs | 1 + library/std/src/num/f64.rs | 1 + 8 files changed, 24 insertions(+) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index d833653fdba6..49b57d4791de 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -508,6 +508,7 @@ pub const fn is_normal(self) -> bool { /// ``` #[inline] #[unstable(feature = "f128", issue = "116909")] + #[must_use] pub const fn classify(self) -> FpCategory { let bits = self.to_bits(); match (bits & Self::MAN_MASK, bits & Self::EXP_MASK) { @@ -608,6 +609,7 @@ pub const fn is_sign_negative(self) -> bool { #[inline] #[doc(alias = "nextUp")] #[unstable(feature = "f128", issue = "116909")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -662,6 +664,7 @@ pub const fn next_up(self) -> Self { #[inline] #[doc(alias = "nextDown")] #[unstable(feature = "f128", issue = "116909")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -907,6 +910,8 @@ pub const fn minimum(self, other: f128) -> f128 { #[doc(alias = "average")] #[unstable(feature = "f128", issue = "116909")] #[rustc_const_unstable(feature = "f128", issue = "116909")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] pub const fn midpoint(self, other: f128) -> f128 { const HI: f128 = f128::MAX / 2.; diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index b0664abcdc73..e3f546926f48 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -500,6 +500,7 @@ pub const fn is_normal(self) -> bool { /// ``` #[inline] #[unstable(feature = "f16", issue = "116909")] + #[must_use] pub const fn classify(self) -> FpCategory { let b = self.to_bits(); match (b & Self::MAN_MASK, b & Self::EXP_MASK) { @@ -604,6 +605,7 @@ pub const fn is_sign_negative(self) -> bool { #[inline] #[doc(alias = "nextUp")] #[unstable(feature = "f16", issue = "116909")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -658,6 +660,7 @@ pub const fn next_up(self) -> Self { #[inline] #[doc(alias = "nextDown")] #[unstable(feature = "f16", issue = "116909")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -901,6 +904,8 @@ pub const fn minimum(self, other: f16) -> f16 { #[doc(alias = "average")] #[unstable(feature = "f16", issue = "116909")] #[rustc_const_unstable(feature = "f16", issue = "116909")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] pub const fn midpoint(self, other: f16) -> f16 { const HI: f16 = f16::MAX / 2.; diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index b85bd2b27158..ac4eedaefbdc 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -723,6 +723,7 @@ pub const fn is_normal(self) -> bool { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")] + #[must_use] pub const fn classify(self) -> FpCategory { // We used to have complicated logic here that avoids the simple bit-based tests to work // around buggy codegen for x87 targets (see @@ -822,6 +823,7 @@ pub const fn is_sign_negative(self) -> bool { #[doc(alias = "nextUp")] #[stable(feature = "float_next_up_down", since = "1.86.0")] #[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -873,6 +875,7 @@ pub const fn next_up(self) -> Self { #[doc(alias = "nextDown")] #[stable(feature = "float_next_up_down", since = "1.86.0")] #[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -1089,6 +1092,8 @@ pub const fn minimum(self, other: f32) -> f32 { #[doc(alias = "average")] #[stable(feature = "num_midpoint", since = "1.85.0")] #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] pub const fn midpoint(self, other: f32) -> f32 { cfg_select! { // Allow faster implementation that have known good 64-bit float diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 3e7c1e792ace..8682774aa3ae 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -722,6 +722,7 @@ pub const fn is_normal(self) -> bool { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")] + #[must_use] pub const fn classify(self) -> FpCategory { // We used to have complicated logic here that avoids the simple bit-based tests to work // around buggy codegen for x87 targets (see @@ -839,6 +840,7 @@ pub fn is_negative(self) -> bool { #[doc(alias = "nextUp")] #[stable(feature = "float_next_up_down", since = "1.86.0")] #[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -890,6 +892,7 @@ pub const fn next_up(self) -> Self { #[doc(alias = "nextDown")] #[stable(feature = "float_next_up_down", since = "1.86.0")] #[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")] + #[must_use = "method returns a new number and does not mutate the original value"] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -1107,6 +1110,8 @@ pub const fn minimum(self, other: f64) -> f64 { #[doc(alias = "average")] #[stable(feature = "num_midpoint", since = "1.85.0")] #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] pub const fn midpoint(self, other: f64) -> f64 { const HI: f64 = f64::MAX / 2.; diff --git a/library/std/src/num/f128.rs b/library/std/src/num/f128.rs index d7c7a82674bf..7b3221bc0fca 100644 --- a/library/std/src/num/f128.rs +++ b/library/std/src/num/f128.rs @@ -643,6 +643,7 @@ pub fn atan2(self, other: f128) -> f128 { #[doc(alias = "sincos")] #[rustc_allow_incoherent_impl] #[unstable(feature = "f128", issue = "116909")] + #[must_use = "this returns the result of the operation, without modifying the original"] pub fn sin_cos(self) -> (f128, f128) { (self.sin(), self.cos()) } diff --git a/library/std/src/num/f16.rs b/library/std/src/num/f16.rs index ef610eacb05d..9ac0e11a4948 100644 --- a/library/std/src/num/f16.rs +++ b/library/std/src/num/f16.rs @@ -608,6 +608,7 @@ pub fn atan2(self, other: f16) -> f16 { #[doc(alias = "sincos")] #[rustc_allow_incoherent_impl] #[unstable(feature = "f16", issue = "116909")] + #[must_use = "this returns the result of the operation, without modifying the original"] pub fn sin_cos(self) -> (f16, f16) { (self.sin(), self.cos()) } diff --git a/library/std/src/num/f32.rs b/library/std/src/num/f32.rs index 771a0cae6dcd..4f38d3be52f7 100644 --- a/library/std/src/num/f32.rs +++ b/library/std/src/num/f32.rs @@ -907,6 +907,7 @@ pub fn atan2(self, other: f32) -> f32 { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] + #[must_use = "this returns the result of the operation, without modifying the original"] pub fn sin_cos(self) -> (f32, f32) { (self.sin(), self.cos()) } diff --git a/library/std/src/num/f64.rs b/library/std/src/num/f64.rs index 59ef39a382b2..8a771185f6fe 100644 --- a/library/std/src/num/f64.rs +++ b/library/std/src/num/f64.rs @@ -907,6 +907,7 @@ pub fn atan2(self, other: f64) -> f64 { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] + #[must_use = "this returns the result of the operation, without modifying the original"] pub fn sin_cos(self) -> (f64, f64) { (self.sin(), self.cos()) }