diff options
| author | John Kugelman <john@kugelman.name> | 2021-10-10 18:22:40 -0400 |
|---|---|---|
| committer | John Kugelman <john@kugelman.name> | 2021-10-10 19:00:33 -0400 |
| commit | cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40 (patch) | |
| tree | 87acd2edbff6d167abc4e8e70c702da9b9e350fa /library/core/src/str | |
| parent | 6928fafe06e4ab29317f75194e1bf67c119dccdc (diff) | |
| download | rust-cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40.tar.gz rust-cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40.zip | |
Add #[must_use] to from_value conversions
Diffstat (limited to 'library/core/src/str')
| -rw-r--r-- | library/core/src/str/converts.rs | 2 | ||||
| -rw-r--r-- | library/core/src/str/lossy.rs | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index da6ef1b6678..ed9f49f1596 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -155,6 +155,7 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { /// assert_eq!("💖", sparkle_heart); /// ``` #[inline] +#[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_from_utf8_unchecked", since = "1.55.0")] pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { @@ -181,6 +182,7 @@ pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { /// assert_eq!("💖", heart); /// ``` #[inline] +#[must_use] #[stable(feature = "str_mut_extras", since = "1.20.0")] pub unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str { // SAFETY: the caller must guarantee that the bytes `v` diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 720a35bbc8f..d3c9d21c3c7 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -12,10 +12,12 @@ pub struct Utf8Lossy { } impl Utf8Lossy { + #[must_use] pub fn from_str(s: &str) -> &Utf8Lossy { Utf8Lossy::from_bytes(s.as_bytes()) } + #[must_use] pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy { // SAFETY: Both use the same memory layout, and UTF-8 correctness isn't required. unsafe { mem::transmute(bytes) } |
