about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-16 00:01:13 -0700
committerGitHub <noreply@github.com>2020-07-16 00:01:13 -0700
commita77813b8d0866a474a9a853d5a479ebc052bef06 (patch)
treeb47df8dd7e6cd3c15ea3dc06e71037ddf1c32e42
parent4b4ea686ff3a0f44b5b2fef04a34ad27832617af (diff)
parent6da69ec08c4ba0c166d28a65196832f8de877149 (diff)
downloadrust-a77813b8d0866a474a9a853d5a479ebc052bef06.tar.gz
rust-a77813b8d0866a474a9a853d5a479ebc052bef06.zip
Rollup merge of #74381 - mbrubeck:docs, r=Mark-Simulacrum
Update docs for str::as_bytes_mut.

* Add "Safety" section describing UTF-8 invariant.

* Remove mention of `from_utf8_mut`.  It is not necessary to call
  a function to convert the byte slice back to a string slice.  The
  original string becomes accessible again after the byte slice is
  no longer used (as shown in the example code).
-rw-r--r--src/libcore/str/mod.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 393911675c7..86e8d5c42b7 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -2374,11 +2374,14 @@ impl str {
         unsafe { Slices { str: self }.slice }
     }
 
-    /// Converts a mutable string slice to a mutable byte slice. To convert the
-    /// mutable byte slice back into a mutable string slice, use the
-    /// [`str::from_utf8_mut`] function.
+    /// Converts a mutable string slice to a mutable byte slice.
     ///
-    /// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
+    /// # Safety
+    ///
+    /// The caller must ensure that the content of the slice is valid UTF-8
+    /// before the borrow ends and the underlying `str` is used.
+    ///
+    /// Use of a `str` whose contents are not valid UTF-8 is undefined behavior.
     ///
     /// # Examples
     ///