Skip to content

Commit f34b849

Browse files
authored
Rollup merge of #89720 - jkugelman:must-use-math-operations, r=joshtriplett
Add #[must_use] to math and bit manipulation methods Also tidied up a few other nearby `#[must_use]`s. Parent issue: #89692
2 parents 98c5279 + bc9d13e commit f34b849

File tree

8 files changed

+255
-19
lines changed

8 files changed

+255
-19
lines changed

library/core/src/num/f32.rs

+14
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ impl f32 {
643643
///
644644
/// assert!(abs_difference <= f32::EPSILON);
645645
/// ```
646+
#[must_use = "this returns the result of the operation, \
647+
without modifying the original"]
646648
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
647649
#[inline]
648650
pub fn to_degrees(self) -> f32 {
@@ -660,6 +662,8 @@ impl f32 {
660662
///
661663
/// assert!(abs_difference <= f32::EPSILON);
662664
/// ```
665+
#[must_use = "this returns the result of the operation, \
666+
without modifying the original"]
663667
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
664668
#[inline]
665669
pub fn to_radians(self) -> f32 {
@@ -719,6 +723,8 @@ impl f32 {
719723
/// * Not be `NaN`
720724
/// * Not be infinite
721725
/// * Be representable in the return type `Int`, after truncating off its fractional part
726+
#[must_use = "this returns the result of the operation, \
727+
without modifying the original"]
722728
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
723729
#[inline]
724730
pub unsafe fn to_int_unchecked<Int>(self) -> Int
@@ -747,6 +753,8 @@ impl f32 {
747753
/// assert_eq!((12.5f32).to_bits(), 0x41480000);
748754
///
749755
/// ```
756+
#[must_use = "this returns the result of the operation, \
757+
without modifying the original"]
750758
#[stable(feature = "float_bits_conv", since = "1.20.0")]
751759
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
752760
#[inline]
@@ -809,6 +817,8 @@ impl f32 {
809817
/// let bytes = 12.5f32.to_be_bytes();
810818
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
811819
/// ```
820+
#[must_use = "this returns the result of the operation, \
821+
without modifying the original"]
812822
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
813823
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
814824
#[inline]
@@ -825,6 +835,8 @@ impl f32 {
825835
/// let bytes = 12.5f32.to_le_bytes();
826836
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
827837
/// ```
838+
#[must_use = "this returns the result of the operation, \
839+
without modifying the original"]
828840
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
829841
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
830842
#[inline]
@@ -854,6 +866,8 @@ impl f32 {
854866
/// }
855867
/// );
856868
/// ```
869+
#[must_use = "this returns the result of the operation, \
870+
without modifying the original"]
857871
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
858872
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
859873
#[inline]

library/core/src/num/f64.rs

+14
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ impl f64 {
658658
///
659659
/// assert!(abs_difference < 1e-10);
660660
/// ```
661+
#[must_use = "this returns the result of the operation, \
662+
without modifying the original"]
661663
#[stable(feature = "rust1", since = "1.0.0")]
662664
#[inline]
663665
pub fn to_degrees(self) -> f64 {
@@ -676,6 +678,8 @@ impl f64 {
676678
///
677679
/// assert!(abs_difference < 1e-10);
678680
/// ```
681+
#[must_use = "this returns the result of the operation, \
682+
without modifying the original"]
679683
#[stable(feature = "rust1", since = "1.0.0")]
680684
#[inline]
681685
pub fn to_radians(self) -> f64 {
@@ -735,6 +739,8 @@ impl f64 {
735739
/// * Not be `NaN`
736740
/// * Not be infinite
737741
/// * Be representable in the return type `Int`, after truncating off its fractional part
742+
#[must_use = "this returns the result of the operation, \
743+
without modifying the original"]
738744
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
739745
#[inline]
740746
pub unsafe fn to_int_unchecked<Int>(self) -> Int
@@ -763,6 +769,8 @@ impl f64 {
763769
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
764770
///
765771
/// ```
772+
#[must_use = "this returns the result of the operation, \
773+
without modifying the original"]
766774
#[stable(feature = "float_bits_conv", since = "1.20.0")]
767775
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
768776
#[inline]
@@ -825,6 +833,8 @@ impl f64 {
825833
/// let bytes = 12.5f64.to_be_bytes();
826834
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
827835
/// ```
836+
#[must_use = "this returns the result of the operation, \
837+
without modifying the original"]
828838
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
829839
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
830840
#[inline]
@@ -841,6 +851,8 @@ impl f64 {
841851
/// let bytes = 12.5f64.to_le_bytes();
842852
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
843853
/// ```
854+
#[must_use = "this returns the result of the operation, \
855+
without modifying the original"]
844856
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
845857
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
846858
#[inline]
@@ -870,6 +882,8 @@ impl f64 {
870882
/// }
871883
/// );
872884
/// ```
885+
#[must_use = "this returns the result of the operation, \
886+
without modifying the original"]
873887
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
874888
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
875889
#[inline]

0 commit comments

Comments
 (0)