diff options
| author | John Kugelman <john@kugelman.name> | 2021-10-11 19:04:24 -0400 |
|---|---|---|
| committer | John Kugelman <john@kugelman.name> | 2021-10-11 19:37:16 -0400 |
| commit | 0cf84c8c19753d9614efcde455f5f987b2a43e90 (patch) | |
| tree | 8fdf3e80c302f37ec8df2900d4c9d33a543f3a0f /library/std/src/ffi | |
| parent | 5b210643ebf2485aafdf2494de8cf41941a64e95 (diff) | |
| download | rust-0cf84c8c19753d9614efcde455f5f987b2a43e90.tar.gz rust-0cf84c8c19753d9614efcde455f5f987b2a43e90.zip | |
Add #[must_use] to to_value conversions
Diffstat (limited to 'library/std/src/ffi')
| -rw-r--r-- | library/std/src/ffi/c_str.rs | 6 | ||||
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index 8b51c4450c2..b6cc388a1dd 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -1337,6 +1337,8 @@ impl CStr { /// assert_eq!(cstr.to_bytes(), b"foo"); /// ``` #[inline] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] pub fn to_bytes(&self) -> &[u8] { let bytes = self.to_bytes_with_nul(); @@ -1362,6 +1364,8 @@ impl CStr { /// assert_eq!(cstr.to_bytes_with_nul(), b"foo\0"); /// ``` #[inline] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] pub fn to_bytes_with_nul(&self) -> &[u8] { unsafe { &*(&self.inner as *const [c_char] as *const [u8]) } @@ -1432,6 +1436,8 @@ impl CStr { /// Cow::Owned(String::from("Hello �World")) as Cow<'_, str> /// ); /// ``` + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[stable(feature = "cstr_to_str", since = "1.4.0")] pub fn to_string_lossy(&self) -> Cow<'_, str> { String::from_utf8_lossy(self.to_bytes()) diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index de745f21649..2828b2a8e45 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -575,6 +575,8 @@ impl OsStr { /// assert_eq!(os_str.to_str(), Some("foo")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[inline] pub fn to_str(&self) -> Option<&str> { self.inner.to_str() @@ -626,6 +628,8 @@ impl OsStr { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[inline] pub fn to_string_lossy(&self) -> Cow<'_, str> { self.inner.to_string_lossy() @@ -643,6 +647,8 @@ impl OsStr { /// assert_eq!(os_string, OsString::from("foo")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] #[inline] pub fn to_os_string(&self) -> OsString { OsString { inner: self.inner.to_owned() } |
