Skip to content

Commit cf2bcd1

Browse files
committed
Add #[must_use] to from_value conversions
1 parent 6928faf commit cf2bcd1

File tree

17 files changed

+50
-1
lines changed

17 files changed

+50
-1
lines changed

library/alloc/src/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ impl str {
595595
/// assert_eq!("☺", &*smile);
596596
/// ```
597597
#[stable(feature = "str_box_extras", since = "1.20.0")]
598+
#[must_use]
598599
#[inline]
599600
pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> {
600601
unsafe { Box::from_raw(Box::into_raw(v) as *mut str) }

library/alloc/src/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ impl String {
761761
/// assert_eq!("💖", sparkle_heart);
762762
/// ```
763763
#[inline]
764+
#[must_use]
764765
#[stable(feature = "rust1", since = "1.0.0")]
765766
pub unsafe fn from_utf8_unchecked(bytes: Vec<u8>) -> String {
766767
String { vec: bytes }

library/core/src/alloc/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ impl Layout {
9494
/// [`Layout::from_size_align`].
9595
#[stable(feature = "alloc_layout", since = "1.28.0")]
9696
#[rustc_const_stable(feature = "alloc_layout", since = "1.36.0")]
97+
#[must_use]
9798
#[inline]
9899
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
99100
// SAFETY: the caller must ensure that `align` is greater than zero.

library/core/src/char/convert.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use super::MAX;
4848
/// assert_eq!(None, c);
4949
/// ```
5050
#[doc(alias = "chr")]
51+
#[must_use]
5152
#[inline]
5253
#[stable(feature = "rust1", since = "1.0.0")]
5354
pub fn from_u32(i: u32) -> Option<char> {
@@ -88,6 +89,7 @@ pub fn from_u32(i: u32) -> Option<char> {
8889
/// assert_eq!('❤', c);
8990
/// ```
9091
#[inline]
92+
#[must_use]
9193
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
9294
pub unsafe fn from_u32_unchecked(i: u32) -> char {
9395
// SAFETY: the caller must guarantee that `i` is a valid char value.
@@ -319,6 +321,7 @@ impl fmt::Display for CharTryFromError {
319321
/// let c = char::from_digit(1, 37);
320322
/// ```
321323
#[inline]
324+
#[must_use]
322325
#[stable(feature = "rust1", since = "1.0.0")]
323326
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
324327
if radix > 36 {

library/core/src/char/methods.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl char {
136136
/// assert_eq!(None, c);
137137
/// ```
138138
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
139+
#[must_use]
139140
#[inline]
140141
pub fn from_u32(i: u32) -> Option<char> {
141142
super::convert::from_u32(i)
@@ -177,6 +178,7 @@ impl char {
177178
/// assert_eq!('❤', c);
178179
/// ```
179180
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
181+
#[must_use]
180182
#[inline]
181183
pub unsafe fn from_u32_unchecked(i: u32) -> char {
182184
// SAFETY: the safety contract must be upheld by the caller.
@@ -230,9 +232,10 @@ impl char {
230232
/// use std::char;
231233
///
232234
/// // this panics
233-
/// char::from_digit(1, 37);
235+
/// let _c = char::from_digit(1, 37);
234236
/// ```
235237
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
238+
#[must_use]
236239
#[inline]
237240
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
238241
super::convert::from_digit(num, radix)

library/core/src/num/f32.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ impl f32 {
786786
/// ```
787787
#[stable(feature = "float_bits_conv", since = "1.20.0")]
788788
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
789+
#[must_use]
789790
#[inline]
790791
pub const fn from_bits(v: u32) -> Self {
791792
// SAFETY: `u32` is a plain old datatype so we can always transmute from it
@@ -864,6 +865,7 @@ impl f32 {
864865
/// ```
865866
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
866867
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
868+
#[must_use]
867869
#[inline]
868870
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self {
869871
Self::from_bits(u32::from_be_bytes(bytes))
@@ -879,6 +881,7 @@ impl f32 {
879881
/// ```
880882
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
881883
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
884+
#[must_use]
882885
#[inline]
883886
pub const fn from_le_bytes(bytes: [u8; 4]) -> Self {
884887
Self::from_bits(u32::from_le_bytes(bytes))
@@ -905,6 +908,7 @@ impl f32 {
905908
/// ```
906909
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
907910
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
911+
#[must_use]
908912
#[inline]
909913
pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self {
910914
Self::from_bits(u32::from_ne_bytes(bytes))

library/core/src/num/f64.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ impl f64 {
800800
/// ```
801801
#[stable(feature = "float_bits_conv", since = "1.20.0")]
802802
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
803+
#[must_use]
803804
#[inline]
804805
pub const fn from_bits(v: u64) -> Self {
805806
// SAFETY: `u64` is a plain old datatype so we can always transmute from it
@@ -878,6 +879,7 @@ impl f64 {
878879
/// ```
879880
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
880881
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
882+
#[must_use]
881883
#[inline]
882884
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self {
883885
Self::from_bits(u64::from_be_bytes(bytes))
@@ -893,6 +895,7 @@ impl f64 {
893895
/// ```
894896
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
895897
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
898+
#[must_use]
896899
#[inline]
897900
pub const fn from_le_bytes(bytes: [u8; 8]) -> Self {
898901
Self::from_bits(u64::from_le_bytes(bytes))
@@ -919,6 +922,7 @@ impl f64 {
919922
/// ```
920923
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
921924
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
925+
#[must_use]
922926
#[inline]
923927
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self {
924928
Self::from_bits(u64::from_ne_bytes(bytes))

library/core/src/num/int_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ macro_rules! int_impl {
282282
/// ```
283283
#[stable(feature = "rust1", since = "1.0.0")]
284284
#[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
285+
#[must_use]
285286
#[inline]
286287
pub const fn from_be(x: Self) -> Self {
287288
#[cfg(target_endian = "big")]
@@ -313,6 +314,7 @@ macro_rules! int_impl {
313314
/// ```
314315
#[stable(feature = "rust1", since = "1.0.0")]
315316
#[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
317+
#[must_use]
316318
#[inline]
317319
pub const fn from_le(x: Self) -> Self {
318320
#[cfg(target_endian = "little")]
@@ -2620,6 +2622,7 @@ macro_rules! int_impl {
26202622
/// ```
26212623
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
26222624
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2625+
#[must_use]
26232626
#[inline]
26242627
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
26252628
Self::from_be(Self::from_ne_bytes(bytes))
@@ -2650,6 +2653,7 @@ macro_rules! int_impl {
26502653
/// ```
26512654
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
26522655
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2656+
#[must_use]
26532657
#[inline]
26542658
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
26552659
Self::from_le(Self::from_ne_bytes(bytes))
@@ -2691,6 +2695,7 @@ macro_rules! int_impl {
26912695
/// ```
26922696
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
26932697
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2698+
#[must_use]
26942699
// SAFETY: const sound because integers are plain old datatypes so we can always
26952700
// transmute to them
26962701
#[inline]

library/core/src/num/saturating.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ macro_rules! saturating_int_impl {
644644
/// }
645645
/// ```
646646
#[inline]
647+
#[must_use]
647648
#[unstable(feature = "saturating_int_impl", issue = "87920")]
648649
pub const fn from_be(x: Self) -> Self {
649650
Saturating(<$t>::from_be(x.0))
@@ -671,6 +672,7 @@ macro_rules! saturating_int_impl {
671672
/// }
672673
/// ```
673674
#[inline]
675+
#[must_use]
674676
#[unstable(feature = "saturating_int_impl", issue = "87920")]
675677
pub const fn from_le(x: Self) -> Self {
676678
Saturating(<$t>::from_le(x.0))

library/core/src/num/uint_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ macro_rules! uint_impl {
285285
/// ```
286286
#[stable(feature = "rust1", since = "1.0.0")]
287287
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
288+
#[must_use]
288289
#[inline(always)]
289290
pub const fn from_be(x: Self) -> Self {
290291
#[cfg(target_endian = "big")]
@@ -317,6 +318,7 @@ macro_rules! uint_impl {
317318
/// ```
318319
#[stable(feature = "rust1", since = "1.0.0")]
319320
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
321+
#[must_use]
320322
#[inline(always)]
321323
pub const fn from_le(x: Self) -> Self {
322324
#[cfg(target_endian = "little")]
@@ -2278,6 +2280,7 @@ macro_rules! uint_impl {
22782280
/// ```
22792281
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
22802282
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2283+
#[must_use]
22812284
#[inline]
22822285
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
22832286
Self::from_be(Self::from_ne_bytes(bytes))
@@ -2308,6 +2311,7 @@ macro_rules! uint_impl {
23082311
/// ```
23092312
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
23102313
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2314+
#[must_use]
23112315
#[inline]
23122316
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
23132317
Self::from_le(Self::from_ne_bytes(bytes))
@@ -2349,6 +2353,7 @@ macro_rules! uint_impl {
23492353
/// ```
23502354
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
23512355
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
2356+
#[must_use]
23522357
// SAFETY: const sound because integers are plain old datatypes so we can always
23532358
// transmute to them
23542359
#[inline]

0 commit comments

Comments
 (0)