diff options
| author | John Kugelman <john@kugelman.name> | 2021-10-11 13:57:38 -0400 |
|---|---|---|
| committer | John Kugelman <john@kugelman.name> | 2021-10-11 13:57:38 -0400 |
| commit | 06e625f7d582601f5e2ff69ba80f6d3a11632b24 (patch) | |
| tree | d2b9b88fb89cf0f074feeaa191cb9e22a4a9eee5 /library/std/src/ffi | |
| parent | 86d6d2b7389fe1b339402c1798edae8b695fc9ef (diff) | |
| download | rust-06e625f7d582601f5e2ff69ba80f6d3a11632b24.tar.gz rust-06e625f7d582601f5e2ff69ba80f6d3a11632b24.zip | |
Add #[must_use] to as_type conversions
Diffstat (limited to 'library/std/src/ffi')
| -rw-r--r-- | library/std/src/ffi/c_str.rs | 5 | ||||
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 1 |
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 6b488e49ed7..8bf9f5dae6e 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -297,6 +297,7 @@ impl FromVecWithNulError { /// /// assert_eq!(&bytes[..], value.unwrap_err().as_bytes()); /// ``` + #[must_use] pub fn as_bytes(&self) -> &[u8] { &self.bytes[..] } @@ -616,6 +617,7 @@ impl CString { /// assert_eq!(bytes, &[b'f', b'o', b'o']); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes(&self) -> &[u8] { // SAFETY: CString has a length at least 1 @@ -635,6 +637,7 @@ impl CString { /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes_with_nul(&self) -> &[u8] { &self.inner @@ -653,6 +656,7 @@ impl CString { /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed")); /// ``` #[inline] + #[must_use] #[stable(feature = "as_c_str", since = "1.20.0")] pub fn as_c_str(&self) -> &CStr { &*self @@ -1308,6 +1312,7 @@ impl CStr { /// This way, the lifetime of the [`CString`] in `hello` encompasses /// the lifetime of `ptr` and the `unsafe` block. #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")] pub const fn as_ptr(&self) -> *const c_char { diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index f5cef60e126..844d866b3dd 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -136,6 +136,7 @@ impl OsString { /// assert_eq!(os_string.as_os_str(), os_str); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn as_os_str(&self) -> &OsStr { self |
