diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-10-11 14:11:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-11 14:11:45 +0200 |
| commit | 96ffc74fe3f7dfc85d165d08b040634ce9400e33 (patch) | |
| tree | dff03f4122cf0b6f2fd61862b5e04adf542a2919 /library/alloc/src | |
| parent | 9183942e8383b4a2c40f8eeb872c71ab3d8c60fe (diff) | |
| parent | cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40 (diff) | |
| download | rust-96ffc74fe3f7dfc85d165d08b040634ce9400e33.tar.gz rust-96ffc74fe3f7dfc85d165d08b040634ce9400e33.zip | |
Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, r=joshtriplett
Add #[must_use] to from_value conversions
I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument.
```rust
core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;
std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString;
```
I put a custom note on `from_raw`:
```rust
#[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"]
pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
```
Parent issue: #89692
r? ``@joshtriplett``
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/str.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/string.rs | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 2900d01d9bd..ac7f2304456 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -595,6 +595,7 @@ impl str { /// assert_eq!("☺", &*smile); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] +#[must_use] #[inline] pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> { unsafe { Box::from_raw(Box::into_raw(v) as *mut str) } diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 7d6609785a0..f11fa92766f 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -764,6 +764,7 @@ impl String { /// assert_eq!("💖", sparkle_heart); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_utf8_unchecked(bytes: Vec<u8>) -> String { String { vec: bytes } |
