Rollup merge of #154979 - ArtemIsmagilov:must-use-floats, r=jhpratt

add #[must_use] macros for floats

try resolve rust-lang/rust#154854
This commit is contained in:
Jonathan Brouwer
2026-04-19 16:04:33 +02:00
committed by GitHub
8 changed files with 24 additions and 0 deletions
+5
View File
@@ -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.;
+5
View File
@@ -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.;
+5
View File
@@ -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
+5
View File
@@ -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.;
+1
View File
@@ -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())
}
+1
View File
@@ -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())
}
+1
View File
@@ -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())
}
+1
View File
@@ -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())
}