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``
This commit is contained in:
commit
96ffc74fe3
17 changed files with 50 additions and 1 deletions
|
@ -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) }
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue