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.
This commit is contained in:
Mark Simulacrum 2018-06-02 19:55:08 -06:00 committed by GitHub
commit 5bbe1ebe00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -1326,6 +1326,7 @@ fn test_str_default() {
t::<&str>();
t::<String>();
t::<&mut str>();
}
#[test]

View File

@ -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.
///