Skip to content

Commit bc9d13e

Browse files
committed
Add #[must_use] to math and bit manipulation methods
Also tidied up a few other nearby `#[must_use]`s.
1 parent bb918d0 commit bc9d13e

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
@@ -636,6 +636,8 @@ impl f32 {
636636
///
637637
/// assert!(abs_difference <= f32::EPSILON);
638638
/// ```
639+
#[must_use = "this returns the result of the operation, \
640+
without modifying the original"]
639641
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
640642
#[inline]
641643
pub fn to_degrees(self) -> f32 {
@@ -653,6 +655,8 @@ impl f32 {
653655
///
654656
/// assert!(abs_difference <= f32::EPSILON);
655657
/// ```
658+
#[must_use = "this returns the result of the operation, \
659+
without modifying the original"]
656660
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
657661
#[inline]
658662
pub fn to_radians(self) -> f32 {
@@ -712,6 +716,8 @@ impl f32 {
712716
/// * Not be `NaN`
713717
/// * Not be infinite
714718
/// * Be representable in the return type `Int`, after truncating off its fractional part
719+
#[must_use = "this returns the result of the operation, \
720+
without modifying the original"]
715721
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
716722
#[inline]
717723
pub unsafe fn to_int_unchecked<Int>(self) -> Int
@@ -740,6 +746,8 @@ impl f32 {
740746
/// assert_eq!((12.5f32).to_bits(), 0x41480000);
741747
///
742748
/// ```
749+
#[must_use = "this returns the result of the operation, \
750+
without modifying the original"]
743751
#[stable(feature = "float_bits_conv", since = "1.20.0")]
744752
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
745753
#[inline]
@@ -802,6 +810,8 @@ impl f32 {
802810
/// let bytes = 12.5f32.to_be_bytes();
803811
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
804812
/// ```
813+
#[must_use = "this returns the result of the operation, \
814+
without modifying the original"]
805815
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
806816
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
807817
#[inline]
@@ -818,6 +828,8 @@ impl f32 {
818828
/// let bytes = 12.5f32.to_le_bytes();
819829
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
820830
/// ```
831+
#[must_use = "this returns the result of the operation, \
832+
without modifying the original"]
821833
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
822834
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
823835
#[inline]
@@ -847,6 +859,8 @@ impl f32 {
847859
/// }
848860
/// );
849861
/// ```
862+
#[must_use = "this returns the result of the operation, \
863+
without modifying the original"]
850864
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
851865
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
852866
#[inline]

library/core/src/num/f64.rs

+14
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ impl f64 {
649649
///
650650
/// assert!(abs_difference < 1e-10);
651651
/// ```
652+
#[must_use = "this returns the result of the operation, \
653+
without modifying the original"]
652654
#[stable(feature = "rust1", since = "1.0.0")]
653655
#[inline]
654656
pub fn to_degrees(self) -> f64 {
@@ -667,6 +669,8 @@ impl f64 {
667669
///
668670
/// assert!(abs_difference < 1e-10);
669671
/// ```
672+
#[must_use = "this returns the result of the operation, \
673+
without modifying the original"]
670674
#[stable(feature = "rust1", since = "1.0.0")]
671675
#[inline]
672676
pub fn to_radians(self) -> f64 {
@@ -726,6 +730,8 @@ impl f64 {
726730
/// * Not be `NaN`
727731
/// * Not be infinite
728732
/// * Be representable in the return type `Int`, after truncating off its fractional part
733+
#[must_use = "this returns the result of the operation, \
734+
without modifying the original"]
729735
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
730736
#[inline]
731737
pub unsafe fn to_int_unchecked<Int>(self) -> Int
@@ -754,6 +760,8 @@ impl f64 {
754760
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
755761
///
756762
/// ```
763+
#[must_use = "this returns the result of the operation, \
764+
without modifying the original"]
757765
#[stable(feature = "float_bits_conv", since = "1.20.0")]
758766
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
759767
#[inline]
@@ -816,6 +824,8 @@ impl f64 {
816824
/// let bytes = 12.5f64.to_be_bytes();
817825
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
818826
/// ```
827+
#[must_use = "this returns the result of the operation, \
828+
without modifying the original"]
819829
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
820830
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
821831
#[inline]
@@ -832,6 +842,8 @@ impl f64 {
832842
/// let bytes = 12.5f64.to_le_bytes();
833843
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
834844
/// ```
845+
#[must_use = "this returns the result of the operation, \
846+
without modifying the original"]
835847
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
836848
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
837849
#[inline]
@@ -861,6 +873,8 @@ impl f64 {
861873
/// }
862874
/// );
863875
/// ```
876+
#[must_use = "this returns the result of the operation, \
877+
without modifying the original"]
864878
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
865879
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
866880
#[inline]

0 commit comments

Comments
 (0)