Skip to content

Commit

Permalink
Rollup merge of rust-lang#89720 - jkugelman:must-use-math-operations,…
Browse files Browse the repository at this point in the history
… r=joshtriplett

Add #[must_use] to math and bit manipulation methods

Also tidied up a few other nearby `#[must_use]`s.

Parent issue: rust-lang#89692
  • Loading branch information
matthiaskrgr committed Oct 10, 2021
2 parents 98c5279 + bc9d13e commit f34b849
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 19 deletions.
14 changes: 14 additions & 0 deletions library/core/src/num/f32.rs
Expand Up @@ -643,6 +643,8 @@ impl f32 {
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
#[inline]
pub fn to_degrees(self) -> f32 {
Expand All @@ -660,6 +662,8 @@ impl f32 {
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
#[inline]
pub fn to_radians(self) -> f32 {
Expand Down Expand Up @@ -719,6 +723,8 @@ impl f32 {
/// * Not be `NaN`
/// * Not be infinite
/// * Be representable in the return type `Int`, after truncating off its fractional part
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
#[inline]
pub unsafe fn to_int_unchecked<Int>(self) -> Int
Expand Down Expand Up @@ -747,6 +753,8 @@ impl f32 {
/// assert_eq!((12.5f32).to_bits(), 0x41480000);
///
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down Expand Up @@ -809,6 +817,8 @@ impl f32 {
/// let bytes = 12.5f32.to_be_bytes();
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand All @@ -825,6 +835,8 @@ impl f32 {
/// let bytes = 12.5f32.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down Expand Up @@ -854,6 +866,8 @@ impl f32 {
/// }
/// );
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/num/f64.rs
Expand Up @@ -658,6 +658,8 @@ impl f64 {
///
/// assert!(abs_difference < 1e-10);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_degrees(self) -> f64 {
Expand All @@ -676,6 +678,8 @@ impl f64 {
///
/// assert!(abs_difference < 1e-10);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_radians(self) -> f64 {
Expand Down Expand Up @@ -735,6 +739,8 @@ impl f64 {
/// * Not be `NaN`
/// * Not be infinite
/// * Be representable in the return type `Int`, after truncating off its fractional part
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
#[inline]
pub unsafe fn to_int_unchecked<Int>(self) -> Int
Expand Down Expand Up @@ -763,6 +769,8 @@ impl f64 {
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
///
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down Expand Up @@ -825,6 +833,8 @@ impl f64 {
/// let bytes = 12.5f64.to_be_bytes();
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand All @@ -841,6 +851,8 @@ impl f64 {
/// let bytes = 12.5f64.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down Expand Up @@ -870,6 +882,8 @@ impl f64 {
/// }
/// );
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
Expand Down

0 comments on commit f34b849

Please sign in to comment.