Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #[must_use] to all functions 'fn(float) -> float' #63871

Merged
merged 5 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl f32 {
/// assert_eq!(g.floor(), 3.0);
/// assert_eq!(h.floor(), -4.0);
/// ```
#[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 {
Expand Down Expand Up @@ -73,6 +74,7 @@ impl f32 {
/// assert_eq!(f.ceil(), 4.0);
/// assert_eq!(g.ceil(), 4.0);
/// ```
#[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 {
Expand All @@ -95,6 +97,7 @@ impl f32 {
/// assert_eq!(f.round(), 3.0);
/// assert_eq!(g.round(), -3.0);
/// ```
#[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 {
Expand All @@ -114,6 +117,7 @@ impl f32 {
/// assert_eq!(g.trunc(), 3.0);
/// assert_eq!(h.trunc(), -3.0);
/// ```
#[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 {
Expand All @@ -135,6 +139,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]
pub fn fract(self) -> f32 { self - self.trunc() }
Expand All @@ -158,6 +163,7 @@ impl f32 {
///
/// assert!(f32::NAN.abs().is_nan());
/// ```
#[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 {
Expand All @@ -182,6 +188,7 @@ impl f32 {
///
/// assert!(f32::NAN.signum().is_nan());
/// ```
#[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 {
Expand Down Expand Up @@ -213,8 +220,8 @@ impl f32 {
///
/// assert!(f32::NAN.copysign(1.0).is_nan());
/// ```
#[must_use = "method returns a new number and does not mutate the original value"]
#[inline]
#[must_use]
#[stable(feature = "copysign", since = "1.35.0")]
pub fn copysign(self, sign: f32) -> f32 {
unsafe { intrinsics::copysignf32(self, sign) }
Expand All @@ -240,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 {
Expand All @@ -263,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 {
Expand Down Expand Up @@ -296,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 {
Expand All @@ -322,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 {
Expand All @@ -340,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 {
Expand Down Expand Up @@ -367,6 +379,7 @@ impl f32 {
/// assert!(abs_difference <= f32::EPSILON);
/// assert!(negative.sqrt().is_nan());
/// ```
#[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 {
Expand All @@ -393,6 +406,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 exp(self) -> f32 {
Expand All @@ -417,6 +431,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 exp2(self) -> f32 {
Expand All @@ -439,6 +454,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 ln(self) -> f32 {
Expand Down Expand Up @@ -467,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() }
Expand All @@ -485,6 +502,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 log2(self) -> f32 {
Expand All @@ -508,6 +526,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 log10(self) -> f32 {
Expand Down Expand Up @@ -537,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",
Expand Down Expand Up @@ -565,6 +585,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 cbrt(self) -> f32 {
Expand All @@ -587,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 {
Expand All @@ -606,6 +628,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 sin(self) -> f32 {
Expand All @@ -629,6 +652,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 cos(self) -> f32 {
Expand All @@ -651,6 +675,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 tan(self) -> f32 {
Expand All @@ -673,6 +698,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 asin(self) -> f32 {
Expand All @@ -695,6 +721,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 acos(self) -> f32 {
Expand All @@ -716,6 +743,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 atan(self) -> f32 {
Expand Down Expand Up @@ -750,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 {
Expand Down Expand Up @@ -794,6 +823,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 exp_m1(self) -> f32 {
Expand All @@ -815,6 +845,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 ln_1p(self) -> f32 {
Expand All @@ -838,6 +869,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 sinh(self) -> f32 {
Expand All @@ -861,6 +893,7 @@ impl f32 {
/// // Same result
/// 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 cosh(self) -> f32 {
Expand All @@ -884,6 +917,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 tanh(self) -> f32 {
Expand All @@ -904,6 +938,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 asinh(self) -> f32 {
Expand All @@ -928,6 +963,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 acosh(self) -> f32 {
Expand All @@ -951,6 +987,7 @@ impl f32 {
///
/// assert!(abs_difference <= 1e-5);
/// ```
#[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 {
Expand Down Expand Up @@ -978,6 +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());
/// ```
// The tests below invoke `clamp` without a return value in order to cause a `panic`.
Copy link
Contributor

@fbstj fbstj Aug 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these worthy of FIXME or some kind of (new?) issue number?

// #[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 {
Expand Down
Loading