about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorJohn Kugelman <john@kugelman.name>2021-10-10 18:22:40 -0400
committerJohn Kugelman <john@kugelman.name>2021-10-10 19:00:33 -0400
commitcf2bcd10ed28b169b8df74383c2a35a4ffbdcf40 (patch)
tree87acd2edbff6d167abc4e8e70c702da9b9e350fa /library/std
parent6928fafe06e4ab29317f75194e1bf67c119dccdc (diff)
downloadrust-cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40.tar.gz
rust-cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40.zip
Add #[must_use] to from_value conversions
Diffstat (limited to 'library/std')
-rw-r--r--library/std/src/ffi/c_str.rs5
-rw-r--r--library/std/src/io/error.rs1
2 files changed, 6 insertions, 0 deletions
diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs
index fe1f28f00c4..e290350993d 100644
--- a/library/std/src/ffi/c_str.rs
+++ b/library/std/src/ffi/c_str.rs
@@ -425,6 +425,7 @@ impl CString {
     ///     let c_string = CString::from_vec_unchecked(raw);
     /// }
     /// ```
+    #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
         v.reserve_exact(1);
@@ -476,6 +477,7 @@ impl CString {
     ///     let c_string = CString::from_raw(raw);
     /// }
     /// ```
+    #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"]
     #[stable(feature = "cstr_memory", since = "1.4.0")]
     pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
         // SAFETY: This is called with a pointer that was obtained from a call
@@ -701,6 +703,7 @@ impl CString {
     ///     unsafe { CString::from_vec_unchecked(b"abc".to_vec()) }
     /// );
     /// ```
+    #[must_use]
     #[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
     pub unsafe fn from_vec_with_nul_unchecked(v: Vec<u8>) -> Self {
         Self { inner: v.into_boxed_slice() }
@@ -1162,6 +1165,7 @@ impl CStr {
     /// }
     /// # }
     /// ```
+    #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
         // SAFETY: The caller has provided a pointer that points to a valid C
@@ -1244,6 +1248,7 @@ impl CStr {
     /// }
     /// ```
     #[inline]
+    #[must_use]
     #[stable(feature = "cstr_from_bytes", since = "1.10.0")]
     #[rustc_const_unstable(feature = "const_cstr_unchecked", issue = "none")]
     pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs
index 51666c0a3c7..57b5c28430f 100644
--- a/library/std/src/io/error.rs
+++ b/library/std/src/io/error.rs
@@ -473,6 +473,7 @@ impl Error {
     /// # }
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[must_use]
     #[inline]
     pub fn from_raw_os_error(code: i32) -> Error {
         Error { repr: Repr::Os(code) }