From 6b02362b32271e90894ede6bfd94909bd1c0b229 Mon Sep 17 00:00:00 2001 From: Kyle Strand Date: Sat, 24 Aug 2019 14:58:01 -0700 Subject: [PATCH 1/5] Add 'must_use' to all functions 'fn(float) -> float' --- src/libstd/f32.rs | 28 ++++++++++++++++++++++++++++ src/libstd/f64.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index e55afc2344f79..d0c64243ee3f5 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -40,6 +40,7 @@ impl f32 { /// assert_eq!(g.floor(), 3.0); /// assert_eq!(h.floor(), -4.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f32 { @@ -73,6 +74,7 @@ impl f32 { /// assert_eq!(f.ceil(), 4.0); /// assert_eq!(g.ceil(), 4.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f32 { @@ -95,6 +97,7 @@ impl f32 { /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f32 { @@ -114,6 +117,7 @@ impl f32 { /// assert_eq!(g.trunc(), 3.0); /// assert_eq!(h.trunc(), -3.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f32 { @@ -135,6 +139,7 @@ impl f32 { /// assert!(abs_difference_x <= f32::EPSILON); /// assert!(abs_difference_y <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f32 { self - self.trunc() } @@ -158,6 +163,7 @@ impl f32 { /// /// assert!(f32::NAN.abs().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn abs(self) -> f32 { @@ -182,6 +188,7 @@ impl f32 { /// /// assert!(f32::NAN.signum().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn signum(self) -> f32 { @@ -367,6 +374,7 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// assert!(negative.sqrt().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f32 { @@ -393,6 +401,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp(self) -> f32 { @@ -417,6 +426,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp2(self) -> f32 { @@ -439,6 +449,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f32 { @@ -485,6 +496,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f32 { @@ -508,6 +520,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f32 { @@ -565,6 +578,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f32 { @@ -606,6 +620,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sin(self) -> f32 { @@ -629,6 +644,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cos(self) -> f32 { @@ -651,6 +667,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tan(self) -> f32 { @@ -673,6 +690,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asin(self) -> f32 { @@ -695,6 +713,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acos(self) -> f32 { @@ -716,6 +735,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan(self) -> f32 { @@ -794,6 +814,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp_m1(self) -> f32 { @@ -815,6 +836,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln_1p(self) -> f32 { @@ -838,6 +860,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sinh(self) -> f32 { @@ -861,6 +884,7 @@ impl f32 { /// // Same result /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cosh(self) -> f32 { @@ -884,6 +908,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tanh(self) -> f32 { @@ -904,6 +929,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f32 { @@ -928,6 +954,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acosh(self) -> f32 { @@ -951,6 +978,7 @@ impl f32 { /// /// assert!(abs_difference <= 1e-5); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atanh(self) -> f32 { diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index b357102630091..0878cfd68b486 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -40,6 +40,7 @@ impl f64 { /// assert_eq!(g.floor(), 3.0); /// assert_eq!(h.floor(), -4.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f64 { @@ -57,6 +58,7 @@ impl f64 { /// assert_eq!(f.ceil(), 4.0); /// assert_eq!(g.ceil(), 4.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f64 { @@ -75,6 +77,7 @@ impl f64 { /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f64 { @@ -94,6 +97,7 @@ impl f64 { /// assert_eq!(g.trunc(), 3.0); /// assert_eq!(h.trunc(), -3.0); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f64 { @@ -113,6 +117,7 @@ impl f64 { /// assert!(abs_difference_x < 1e-10); /// assert!(abs_difference_y < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f64 { self - self.trunc() } @@ -136,6 +141,7 @@ impl f64 { /// /// assert!(f64::NAN.abs().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn abs(self) -> f64 { @@ -160,6 +166,7 @@ impl f64 { /// /// assert!(f64::NAN.signum().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn signum(self) -> f64 { @@ -332,6 +339,7 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// assert!(negative.sqrt().is_nan()); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f64 { @@ -356,6 +364,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp(self) -> f64 { @@ -374,6 +383,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp2(self) -> f64 { @@ -394,6 +404,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f64 { @@ -432,6 +443,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f64 { @@ -455,6 +467,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f64 { @@ -504,6 +517,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f64 { @@ -543,6 +557,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sin(self) -> f64 { @@ -562,6 +577,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cos(self) -> f64 { @@ -580,6 +596,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-14); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tan(self) -> f64 { @@ -602,6 +619,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asin(self) -> f64 { @@ -624,6 +642,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acos(self) -> f64 { @@ -643,6 +662,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan(self) -> f64 { @@ -719,6 +739,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp_m1(self) -> f64 { @@ -740,6 +761,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln_1p(self) -> f64 { @@ -763,6 +785,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sinh(self) -> f64 { @@ -786,6 +809,7 @@ impl f64 { /// // Same result /// assert!(abs_difference < 1.0e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cosh(self) -> f64 { @@ -809,6 +833,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tanh(self) -> f64 { @@ -827,6 +852,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f64 { @@ -849,6 +875,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acosh(self) -> f64 { @@ -872,6 +899,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atanh(self) -> f64 { From ba2a1fa898c4af38469f4861392defcfb1da00bb Mon Sep 17 00:00:00 2001 From: Kyle Strand Date: Wed, 28 Aug 2019 09:37:52 -0600 Subject: [PATCH 2/5] Add reason for each 'must_use' --- src/libstd/f32.rs | 58 +++++++++++++++++++++++------------------------ src/libstd/f64.rs | 58 +++++++++++++++++++++++------------------------ 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index d0c64243ee3f5..3c08b25446638 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -40,7 +40,7 @@ impl f32 { /// assert_eq!(g.floor(), 3.0); /// assert_eq!(h.floor(), -4.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f32 { @@ -74,7 +74,7 @@ impl f32 { /// assert_eq!(f.ceil(), 4.0); /// assert_eq!(g.ceil(), 4.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f32 { @@ -97,7 +97,7 @@ impl f32 { /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f32 { @@ -117,7 +117,7 @@ impl f32 { /// assert_eq!(g.trunc(), 3.0); /// assert_eq!(h.trunc(), -3.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f32 { @@ -139,7 +139,7 @@ impl f32 { /// assert!(abs_difference_x <= f32::EPSILON); /// assert!(abs_difference_y <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f32 { self - self.trunc() } @@ -163,7 +163,7 @@ impl f32 { /// /// assert!(f32::NAN.abs().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn abs(self) -> f32 { @@ -188,7 +188,7 @@ impl f32 { /// /// assert!(f32::NAN.signum().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn signum(self) -> f32 { @@ -221,7 +221,7 @@ impl f32 { /// assert!(f32::NAN.copysign(1.0).is_nan()); /// ``` #[inline] - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "copysign", since = "1.35.0")] pub fn copysign(self, sign: f32) -> f32 { unsafe { intrinsics::copysignf32(self, sign) } @@ -374,7 +374,7 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// assert!(negative.sqrt().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f32 { @@ -401,7 +401,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp(self) -> f32 { @@ -426,7 +426,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp2(self) -> f32 { @@ -449,7 +449,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f32 { @@ -496,7 +496,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f32 { @@ -520,7 +520,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f32 { @@ -578,7 +578,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f32 { @@ -620,7 +620,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sin(self) -> f32 { @@ -644,7 +644,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cos(self) -> f32 { @@ -667,7 +667,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tan(self) -> f32 { @@ -690,7 +690,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asin(self) -> f32 { @@ -713,7 +713,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acos(self) -> f32 { @@ -735,7 +735,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan(self) -> f32 { @@ -814,7 +814,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp_m1(self) -> f32 { @@ -836,7 +836,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln_1p(self) -> f32 { @@ -860,7 +860,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sinh(self) -> f32 { @@ -884,7 +884,7 @@ impl f32 { /// // Same result /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cosh(self) -> f32 { @@ -908,7 +908,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tanh(self) -> f32 { @@ -929,7 +929,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f32 { @@ -954,7 +954,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acosh(self) -> f32 { @@ -978,7 +978,7 @@ impl f32 { /// /// assert!(abs_difference <= 1e-5); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atanh(self) -> f32 { diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 0878cfd68b486..74c81b47bbba1 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -40,7 +40,7 @@ impl f64 { /// assert_eq!(g.floor(), 3.0); /// assert_eq!(h.floor(), -4.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f64 { @@ -58,7 +58,7 @@ impl f64 { /// assert_eq!(f.ceil(), 4.0); /// assert_eq!(g.ceil(), 4.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f64 { @@ -77,7 +77,7 @@ impl f64 { /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f64 { @@ -97,7 +97,7 @@ impl f64 { /// assert_eq!(g.trunc(), 3.0); /// assert_eq!(h.trunc(), -3.0); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f64 { @@ -117,7 +117,7 @@ impl f64 { /// assert!(abs_difference_x < 1e-10); /// assert!(abs_difference_y < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f64 { self - self.trunc() } @@ -141,7 +141,7 @@ impl f64 { /// /// assert!(f64::NAN.abs().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn abs(self) -> f64 { @@ -166,7 +166,7 @@ impl f64 { /// /// assert!(f64::NAN.signum().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn signum(self) -> f64 { @@ -199,7 +199,7 @@ impl f64 { /// assert!(f64::NAN.copysign(1.0).is_nan()); /// ``` #[inline] - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "copysign", since = "1.35.0")] pub fn copysign(self, sign: f64) -> f64 { unsafe { intrinsics::copysignf64(self, sign) } @@ -339,7 +339,7 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// assert!(negative.sqrt().is_nan()); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f64 { @@ -364,7 +364,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp(self) -> f64 { @@ -383,7 +383,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp2(self) -> f64 { @@ -404,7 +404,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f64 { @@ -443,7 +443,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f64 { @@ -467,7 +467,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f64 { @@ -517,7 +517,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f64 { @@ -557,7 +557,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sin(self) -> f64 { @@ -577,7 +577,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cos(self) -> f64 { @@ -596,7 +596,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-14); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tan(self) -> f64 { @@ -619,7 +619,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asin(self) -> f64 { @@ -642,7 +642,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acos(self) -> f64 { @@ -662,7 +662,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan(self) -> f64 { @@ -739,7 +739,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp_m1(self) -> f64 { @@ -761,7 +761,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln_1p(self) -> f64 { @@ -785,7 +785,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sinh(self) -> f64 { @@ -809,7 +809,7 @@ impl f64 { /// // Same result /// assert!(abs_difference < 1.0e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cosh(self) -> f64 { @@ -833,7 +833,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn tanh(self) -> f64 { @@ -852,7 +852,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f64 { @@ -875,7 +875,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acosh(self) -> f64 { @@ -899,7 +899,7 @@ impl f64 { /// /// assert!(abs_difference < 1.0e-10); /// ``` - #[must_use] + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atanh(self) -> f64 { From c5b0003d9948ac302631f83e2addfa51db6ac601 Mon Sep 17 00:00:00 2001 From: Kyle Strand Date: Wed, 28 Aug 2019 09:41:45 -0600 Subject: [PATCH 3/5] Annotate functions taking extra args --- src/libstd/f32.rs | 12 +++++++++++- src/libstd/f64.rs | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 3c08b25446638..142558a9f0aa9 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -220,8 +220,8 @@ impl f32 { /// /// assert!(f32::NAN.copysign(1.0).is_nan()); /// ``` - #[inline] #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] #[stable(feature = "copysign", since = "1.35.0")] pub fn copysign(self, sign: f32) -> f32 { unsafe { intrinsics::copysignf32(self, sign) } @@ -247,6 +247,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn mul_add(self, a: f32, b: f32) -> f32 { @@ -270,6 +271,7 @@ impl f32 { /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0 /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0 /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn div_euclid(self, rhs: f32) -> f32 { @@ -303,6 +305,7 @@ impl f32 { /// // limitation due to round-off error /// assert!((-std::f32::EPSILON).rem_euclid(3.0) != 0.0); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn rem_euclid(self, rhs: f32) -> f32 { @@ -329,6 +332,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powi(self, n: i32) -> f32 { @@ -347,6 +351,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powf(self, n: f32) -> f32 { @@ -478,6 +483,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() } @@ -550,6 +556,7 @@ impl f32 { /// assert!(abs_difference_x <= f32::EPSILON); /// assert!(abs_difference_y <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] #[rustc_deprecated(since = "1.10.0", @@ -601,6 +608,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn hypot(self, other: f32) -> f32 { @@ -770,6 +778,7 @@ impl f32 { /// assert!(abs_difference_1 <= f32::EPSILON); /// assert!(abs_difference_2 <= f32::EPSILON); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan2(self, other: f32) -> f32 { @@ -1006,6 +1015,7 @@ impl f32 { /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0); /// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f32, max: f32) -> f32 { diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 74c81b47bbba1..d46cef149f14c 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -198,9 +198,9 @@ impl f64 { /// /// assert!(f64::NAN.copysign(1.0).is_nan()); /// ``` - #[inline] #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "copysign", since = "1.35.0")] + #[inline] pub fn copysign(self, sign: f64) -> f64 { unsafe { intrinsics::copysignf64(self, sign) } } @@ -223,6 +223,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn mul_add(self, a: f64, b: f64) -> f64 { @@ -246,6 +247,7 @@ impl f64 { /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0 /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0 /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn div_euclid(self, rhs: f64) -> f64 { @@ -279,6 +281,7 @@ impl f64 { /// // limitation due to round-off error /// assert!((-std::f64::EPSILON).rem_euclid(3.0) != 0.0); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn rem_euclid(self, rhs: f64) -> f64 { @@ -302,6 +305,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powi(self, n: i32) -> f64 { @@ -318,6 +322,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powf(self, n: f64) -> f64 { @@ -427,6 +432,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log(self, base: f64) -> f64 { self.ln() / base.ln() } @@ -491,6 +497,7 @@ impl f64 { /// assert!(abs_difference_x < 1e-10); /// assert!(abs_difference_y < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] #[rustc_deprecated(since = "1.10.0", @@ -538,6 +545,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn hypot(self, other: f64) -> f64 { @@ -697,6 +705,7 @@ impl f64 { /// assert!(abs_difference_1 < 1e-10); /// assert!(abs_difference_2 < 1e-10); /// ``` + #[must_use = "method returns a new number and does not mutate the original value"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn atan2(self, other: f64) -> f64 { From 54cb728ab8b89ef31578455031519101a93dadc7 Mon Sep 17 00:00:00 2001 From: Kyle Strand Date: Wed, 28 Aug 2019 12:04:32 -0600 Subject: [PATCH 4/5] Let 'clamp' be invoked without using return value; used in tests --- src/libstd/f32.rs | 3 ++- src/libstd/f64.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 142558a9f0aa9..aefe4690b106c 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1015,7 +1015,8 @@ impl f32 { /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0); /// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` - #[must_use = "method returns a new number and does not mutate the original value"] + // The tests below invoke `clamp` without a return value in order to cause a `panic`. + // #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f32, max: f32) -> f32 { diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index d46cef149f14c..0eca1434a637f 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -936,6 +936,8 @@ impl f64 { /// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0); /// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` + // The tests below invoke `clamp` without a return value in order to cause a `panic`. + // #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f64, max: f64) -> f64 { From 1aa5d0cace3a72ae23f32ece5bb18085b36b5258 Mon Sep 17 00:00:00 2001 From: Kyle Strand Date: Thu, 5 Sep 2019 10:22:11 -0600 Subject: [PATCH 5/5] Restore 'must_use' for 'clamp'; fix warning for tests --- src/libstd/f32.rs | 9 ++++----- src/libstd/f64.rs | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index aefe4690b106c..72a8f31cec18b 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1015,8 +1015,7 @@ impl f32 { /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0); /// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` - // The tests below invoke `clamp` without a return value in order to cause a `panic`. - // #[must_use = "method returns a new number and does not mutate the original value"] + #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f32, max: f32) -> f32 { @@ -1631,18 +1630,18 @@ mod tests { #[test] #[should_panic] fn test_clamp_min_greater_than_max() { - 1.0f32.clamp(3.0, 1.0); + let _ = 1.0f32.clamp(3.0, 1.0); } #[test] #[should_panic] fn test_clamp_min_is_nan() { - 1.0f32.clamp(NAN, 1.0); + let _ = 1.0f32.clamp(NAN, 1.0); } #[test] #[should_panic] fn test_clamp_max_is_nan() { - 1.0f32.clamp(3.0, NAN); + let _ = 1.0f32.clamp(3.0, NAN); } } diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 0eca1434a637f..762a87e257279 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -936,8 +936,7 @@ impl f64 { /// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0); /// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` - // The tests below invoke `clamp` without a return value in order to cause a `panic`. - // #[must_use = "method returns a new number and does not mutate the original value"] + #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f64, max: f64) -> f64 { @@ -1571,18 +1570,18 @@ mod tests { #[test] #[should_panic] fn test_clamp_min_greater_than_max() { - 1.0f64.clamp(3.0, 1.0); + let _ = 1.0f64.clamp(3.0, 1.0); } #[test] #[should_panic] fn test_clamp_min_is_nan() { - 1.0f64.clamp(NAN, 1.0); + let _ = 1.0f64.clamp(NAN, 1.0); } #[test] #[should_panic] fn test_clamp_max_is_nan() { - 1.0f64.clamp(3.0, NAN); + let _ = 1.0f64.clamp(3.0, NAN); } }