Skip to content

Commit 607021c

Browse files
add must_use macros
add msg
1 parent 30d0309 commit 607021c

8 files changed

Lines changed: 24 additions & 0 deletions

File tree

library/core/src/num/f128.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ impl f128 {
508508
/// ```
509509
#[inline]
510510
#[unstable(feature = "f128", issue = "116909")]
511+
#[must_use]
511512
pub const fn classify(self) -> FpCategory {
512513
let bits = self.to_bits();
513514
match (bits & Self::MAN_MASK, bits & Self::EXP_MASK) {
@@ -608,6 +609,7 @@ impl f128 {
608609
#[inline]
609610
#[doc(alias = "nextUp")]
610611
#[unstable(feature = "f128", issue = "116909")]
612+
#[must_use = "method returns a new number and does not mutate the original value"]
611613
pub const fn next_up(self) -> Self {
612614
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
613615
// denormals to zero. This is in general unsound and unsupported, but here
@@ -662,6 +664,7 @@ impl f128 {
662664
#[inline]
663665
#[doc(alias = "nextDown")]
664666
#[unstable(feature = "f128", issue = "116909")]
667+
#[must_use = "method returns a new number and does not mutate the original value"]
665668
pub const fn next_down(self) -> Self {
666669
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
667670
// denormals to zero. This is in general unsound and unsupported, but here
@@ -907,6 +910,8 @@ impl f128 {
907910
#[doc(alias = "average")]
908911
#[unstable(feature = "f128", issue = "116909")]
909912
#[rustc_const_unstable(feature = "f128", issue = "116909")]
913+
#[must_use = "this returns the result of the operation, \
914+
without modifying the original"]
910915
pub const fn midpoint(self, other: f128) -> f128 {
911916
const HI: f128 = f128::MAX / 2.;
912917

library/core/src/num/f16.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ impl f16 {
500500
/// ```
501501
#[inline]
502502
#[unstable(feature = "f16", issue = "116909")]
503+
#[must_use]
503504
pub const fn classify(self) -> FpCategory {
504505
let b = self.to_bits();
505506
match (b & Self::MAN_MASK, b & Self::EXP_MASK) {
@@ -604,6 +605,7 @@ impl f16 {
604605
#[inline]
605606
#[doc(alias = "nextUp")]
606607
#[unstable(feature = "f16", issue = "116909")]
608+
#[must_use = "method returns a new number and does not mutate the original value"]
607609
pub const fn next_up(self) -> Self {
608610
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
609611
// denormals to zero. This is in general unsound and unsupported, but here
@@ -658,6 +660,7 @@ impl f16 {
658660
#[inline]
659661
#[doc(alias = "nextDown")]
660662
#[unstable(feature = "f16", issue = "116909")]
663+
#[must_use = "method returns a new number and does not mutate the original value"]
661664
pub const fn next_down(self) -> Self {
662665
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
663666
// denormals to zero. This is in general unsound and unsupported, but here
@@ -901,6 +904,8 @@ impl f16 {
901904
#[doc(alias = "average")]
902905
#[unstable(feature = "f16", issue = "116909")]
903906
#[rustc_const_unstable(feature = "f16", issue = "116909")]
907+
#[must_use = "this returns the result of the operation, \
908+
without modifying the original"]
904909
pub const fn midpoint(self, other: f16) -> f16 {
905910
const HI: f16 = f16::MAX / 2.;
906911

library/core/src/num/f32.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ impl f32 {
723723
/// ```
724724
#[stable(feature = "rust1", since = "1.0.0")]
725725
#[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")]
726+
#[must_use]
726727
pub const fn classify(self) -> FpCategory {
727728
// We used to have complicated logic here that avoids the simple bit-based tests to work
728729
// around buggy codegen for x87 targets (see
@@ -822,6 +823,7 @@ impl f32 {
822823
#[doc(alias = "nextUp")]
823824
#[stable(feature = "float_next_up_down", since = "1.86.0")]
824825
#[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")]
826+
#[must_use = "method returns a new number and does not mutate the original value"]
825827
pub const fn next_up(self) -> Self {
826828
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
827829
// denormals to zero. This is in general unsound and unsupported, but here
@@ -873,6 +875,7 @@ impl f32 {
873875
#[doc(alias = "nextDown")]
874876
#[stable(feature = "float_next_up_down", since = "1.86.0")]
875877
#[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")]
878+
#[must_use = "method returns a new number and does not mutate the original value"]
876879
pub const fn next_down(self) -> Self {
877880
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
878881
// denormals to zero. This is in general unsound and unsupported, but here
@@ -1089,6 +1092,8 @@ impl f32 {
10891092
#[doc(alias = "average")]
10901093
#[stable(feature = "num_midpoint", since = "1.85.0")]
10911094
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
1095+
#[must_use = "this returns the result of the operation, \
1096+
without modifying the original"]
10921097
pub const fn midpoint(self, other: f32) -> f32 {
10931098
cfg_select! {
10941099
// Allow faster implementation that have known good 64-bit float

library/core/src/num/f64.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ impl f64 {
722722
/// ```
723723
#[stable(feature = "rust1", since = "1.0.0")]
724724
#[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")]
725+
#[must_use]
725726
pub const fn classify(self) -> FpCategory {
726727
// We used to have complicated logic here that avoids the simple bit-based tests to work
727728
// around buggy codegen for x87 targets (see
@@ -839,6 +840,7 @@ impl f64 {
839840
#[doc(alias = "nextUp")]
840841
#[stable(feature = "float_next_up_down", since = "1.86.0")]
841842
#[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")]
843+
#[must_use = "method returns a new number and does not mutate the original value"]
842844
pub const fn next_up(self) -> Self {
843845
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
844846
// denormals to zero. This is in general unsound and unsupported, but here
@@ -890,6 +892,7 @@ impl f64 {
890892
#[doc(alias = "nextDown")]
891893
#[stable(feature = "float_next_up_down", since = "1.86.0")]
892894
#[rustc_const_stable(feature = "float_next_up_down", since = "1.86.0")]
895+
#[must_use = "method returns a new number and does not mutate the original value"]
893896
pub const fn next_down(self) -> Self {
894897
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
895898
// denormals to zero. This is in general unsound and unsupported, but here
@@ -1107,6 +1110,8 @@ impl f64 {
11071110
#[doc(alias = "average")]
11081111
#[stable(feature = "num_midpoint", since = "1.85.0")]
11091112
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
1113+
#[must_use = "this returns the result of the operation, \
1114+
without modifying the original"]
11101115
pub const fn midpoint(self, other: f64) -> f64 {
11111116
const HI: f64 = f64::MAX / 2.;
11121117

library/std/src/num/f128.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ impl f128 {
643643
#[doc(alias = "sincos")]
644644
#[rustc_allow_incoherent_impl]
645645
#[unstable(feature = "f128", issue = "116909")]
646+
#[must_use = "this returns the result of the operation, without modifying the original"]
646647
pub fn sin_cos(self) -> (f128, f128) {
647648
(self.sin(), self.cos())
648649
}

library/std/src/num/f16.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ impl f16 {
608608
#[doc(alias = "sincos")]
609609
#[rustc_allow_incoherent_impl]
610610
#[unstable(feature = "f16", issue = "116909")]
611+
#[must_use = "this returns the result of the operation, without modifying the original"]
611612
pub fn sin_cos(self) -> (f16, f16) {
612613
(self.sin(), self.cos())
613614
}

library/std/src/num/f32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ impl f32 {
907907
#[rustc_allow_incoherent_impl]
908908
#[stable(feature = "rust1", since = "1.0.0")]
909909
#[inline]
910+
#[must_use = "this returns the result of the operation, without modifying the original"]
910911
pub fn sin_cos(self) -> (f32, f32) {
911912
(self.sin(), self.cos())
912913
}

library/std/src/num/f64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ impl f64 {
907907
#[rustc_allow_incoherent_impl]
908908
#[stable(feature = "rust1", since = "1.0.0")]
909909
#[inline]
910+
#[must_use = "this returns the result of the operation, without modifying the original"]
910911
pub fn sin_cos(self) -> (f64, f64) {
911912
(self.sin(), self.cos())
912913
}

0 commit comments

Comments
 (0)