diff options
Diffstat (limited to 'library/alloc/src/ffi/c_str.rs')
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 8 | 
1 files changed, 4 insertions, 4 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index f6743c65710..d5b19470e31 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -574,7 +574,7 @@ impl CString { #[stable(feature = "as_c_str", since = "1.20.0")] #[rustc_diagnostic_item = "cstring_as_c_str"] pub fn as_c_str(&self) -> &CStr { - &*self + unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) } } /// Converts this `CString` into a boxed [`CStr`]. @@ -705,14 +705,14 @@ impl ops::Deref for CString { #[inline] fn deref(&self) -> &CStr { - unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) } + self.as_c_str() } } #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for CString { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&**self, f) + fmt::Debug::fmt(self.as_c_str(), f) } } @@ -1116,7 +1116,7 @@ impl CStr { /// with the corresponding <code>&[str]</code> slice. Otherwise, it will /// replace any invalid UTF-8 sequences with /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a - /// <code>[Cow]::[Owned]\(&[str])</code> with the result. + /// <code>[Cow]::[Owned]\([String])</code> with the result. /// /// [str]: prim@str "str" /// [Borrowed]: Cow::Borrowed  | 
