about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Simulacrum <mark.simulacrum@gmail.com>2018-06-02 19:55:08 -0600
committerGitHub <noreply@github.com>2018-06-02 19:55:08 -0600
commit5bbe1ebe00428b77708c4d29989be09963ee2880 (patch)
tree5be90d9b1ebc170531ee1734e20b54191f7777de
parent0c695e01dafa6046660d0e92844827d104aa4ab2 (diff)
parent0ff8d40fa1c6be4428a65f6539ffe98c83245eab (diff)
downloadrust-5bbe1ebe00428b77708c4d29989be09963ee2880.tar.gz
rust-5bbe1ebe00428b77708c4d29989be09963ee2880.zip
Rollup merge of #51306 - kennytm:impl-default-for-mut-str, r=SimonSapin
impl Default for &mut str

Rationale: There is already `impl Default for &mut [T]`.

Note: This impl is insta-stable.
-rw-r--r--src/liballoc/tests/str.rs1
-rw-r--r--src/libcore/str/mod.rs6
2 files changed, 7 insertions, 0 deletions
diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs
index 03d295d16e6..75306ac82df 100644
--- a/src/liballoc/tests/str.rs
+++ b/src/liballoc/tests/str.rs
@@ -1326,6 +1326,7 @@ fn test_str_default() {
 
     t::<&str>();
     t::<String>();
+    t::<&mut str>();
 }
 
 #[test]
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 3169893fcde..5e1a9c25a21 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -3875,6 +3875,12 @@ impl<'a> Default for &'a str {
     fn default() -> &'a str { "" }
 }
 
+#[stable(feature = "default_mut_str", since = "1.28.0")]
+impl<'a> Default for &'a mut str {
+    /// Creates an empty mutable str
+    fn default() -> &'a mut str { unsafe { from_utf8_unchecked_mut(&mut []) } }
+}
+
 /// An iterator over the non-whitespace substrings of a string,
 /// separated by any amount of whitespace.
 ///