diff options
| author | bors <bors@rust-lang.org> | 2021-10-11 07:27:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-10-11 07:27:44 +0000 |
| commit | 86d6d2b7389fe1b339402c1798edae8b695fc9ef (patch) | |
| tree | 88c37951da1bbc2c46818b1705d6fa5e962eae5b /library/std/src | |
| parent | 9a757817c352801de8b0593728f8aee21e23cd53 (diff) | |
| parent | b115781bcd0609e94c08192924853097c73f1a1c (diff) | |
| download | rust-86d6d2b7389fe1b339402c1798edae8b695fc9ef.tar.gz rust-86d6d2b7389fe1b339402c1798edae8b695fc9ef.zip | |
Auto merge of #89755 - jkugelman:must-use-conversions-that-move-self, r=joshtriplett
Add #[must_use] to conversions that move self Everything here got the same message. Is the wording okay? ```rust #[must_use = "`self` will be dropped if the result is not used"] ``` I want to draw attention to these methods in particular: ```rust alloc::sync::Arc<MaybeUninit<T>> unsafe fn assume_init(self) -> Arc<T>; alloc::sync::Arc<[MaybeUninit<T>]> unsafe fn assume_init(self) -> Arc<[T]>; core::pin::Pin<&'a mut T> const fn into_ref(self) -> Pin<&'a T>; core::pin::Pin<&'a mut T> const fn get_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> const unsafe fn get_unchecked_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> unsafe fn map_unchecked_mut(self, func: F) -> Pin<&'a mut U>; core::pin::Pin<&'a mut Pin<P>> fn as_deref_mut(self) -> Pin<&'a mut P::Target>; ``` Parent issue: #89692 r? `@joshtriplett`
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/collections/hash/map.rs | 3 | ||||
| -rw-r--r-- | library/std/src/ffi/c_str.rs | 8 | ||||
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/buffered/bufwriter.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/error.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/stdio.rs | 1 | ||||
| -rw-r--r-- | library/std/src/net/tcp.rs | 1 | ||||
| -rw-r--r-- | library/std/src/path.rs | 3 |
8 files changed, 18 insertions, 1 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 528bb1bf6e9..f0bd09091d7 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1720,6 +1720,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the entry into a mutable reference to the key in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_key(self) -> &'a mut K { self.base.into_key() @@ -1735,6 +1736,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the `OccupiedEntry` into a mutable reference to the value in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_mut(self) -> &'a mut V { self.base.into_mut() @@ -1764,6 +1766,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the `OccupiedEntry` into a mutable reference to the key and value in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_key_value(self) -> (&'a mut K, &'a mut V) { self.base.into_key_value() diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index fe1f28f00c4..6b488e49ed7 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -322,6 +322,7 @@ impl FromVecWithNulError { /// /// assert_eq!(bytes, value.unwrap_err().into_bytes()); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] pub fn into_bytes(self) -> Vec<u8> { self.bytes } @@ -524,6 +525,7 @@ impl CString { /// } /// ``` #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstr_memory", since = "1.4.0")] pub fn into_raw(self) -> *mut c_char { Box::into_raw(self.into_inner()) as *mut c_char @@ -547,7 +549,6 @@ impl CString { /// let err = cstring.into_string().err().expect("into_string().err() failed"); /// assert_eq!(err.utf8_error().valid_up_to(), 1); /// ``` - #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_string(self) -> Result<String, IntoStringError> { String::from_utf8(self.into_bytes()).map_err(|e| IntoStringError { @@ -571,6 +572,7 @@ impl CString { /// let bytes = c_string.into_bytes(); /// assert_eq!(bytes, vec![b'f', b'o', b'o']); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes(self) -> Vec<u8> { let mut vec = self.into_inner().into_vec(); @@ -591,6 +593,7 @@ impl CString { /// let bytes = c_string.into_bytes_with_nul(); /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes_with_nul(self) -> Vec<u8> { self.into_inner().into_vec() @@ -667,6 +670,7 @@ impl CString { /// assert_eq!(&*boxed, /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed")); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "into_boxed_c_str", since = "1.20.0")] pub fn into_boxed_c_str(self) -> Box<CStr> { unsafe { Box::from_raw(Box::into_raw(self.into_inner()) as *mut CStr) } @@ -1018,6 +1022,7 @@ impl NulError { /// let nul_error = CString::new("foo\0bar").unwrap_err(); /// assert_eq!(nul_error.into_vec(), b"foo\0bar"); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_vec(self) -> Vec<u8> { self.1 @@ -1092,6 +1097,7 @@ impl fmt::Display for FromVecWithNulError { impl IntoStringError { /// Consumes this error, returning original [`CString`] which generated the /// error. + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_cstring(self) -> CString { self.inner diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c305519dd44..f5cef60e126 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -346,6 +346,7 @@ impl OsString { /// /// let b: Box<OsStr> = s.into_boxed_os_str(); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "into_boxed_os_str", since = "1.20.0")] pub fn into_boxed_os_str(self) -> Box<OsStr> { let rw = Box::into_raw(self.inner.into_box()) as *mut OsStr; diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index ebbda7c1bf2..c7423e4d92a 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -476,6 +476,7 @@ pub struct WriterPanicked { impl WriterPanicked { /// Returns the perhaps-unwritten data. Some of this data may have been written by the /// panicking call(s) to the underlying writer, so simply writing it again is not a good idea. + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub fn into_inner(self) -> Vec<u8> { self.buf diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 51666c0a3c7..6101260e149 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -657,6 +657,7 @@ impl Error { /// } /// ``` #[stable(feature = "io_error_inner", since = "1.3.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_inner(self) -> Option<Box<dyn error::Error + Send + Sync>> { match self.repr { diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 1ac3bbc95c6..9389501e012 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -464,6 +464,7 @@ impl Stdin { /// println!("got a line: {}", line.unwrap()); /// } /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "stdin_forwarders", issue = "87096")] pub fn lines(self) -> Lines<StdinLock<'static>> { self.into_locked().lines() diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 223726d45d7..2c6e3930059 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -883,6 +883,7 @@ impl TcpListener { /// Ok(()) /// } /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "tcplistener_into_incoming", issue = "88339")] pub fn into_incoming(self) -> IntoIncoming { IntoIncoming { listener: self } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index a45ecf6ea8c..6bfc7b0a5c1 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -532,6 +532,7 @@ impl<'a> Component<'a> { /// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect(); /// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn as_os_str(self) -> &'a OsStr { match self { @@ -1428,6 +1429,7 @@ impl PathBuf { /// let os_str = p.into_os_string(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_os_string(self) -> OsString { self.inner @@ -1435,6 +1437,7 @@ impl PathBuf { /// Converts this `PathBuf` into a [boxed](Box) [`Path`]. #[stable(feature = "into_boxed_path", since = "1.20.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_boxed_path(self) -> Box<Path> { let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path; |
