summaryrefslogtreecommitdiffstats
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index be41919b9..59e3f887b 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -1851,7 +1851,7 @@ impl String {
}
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
- /// `&'static mut str`.
+ /// `&'a mut str`.
///
/// This is mainly useful for data that lives for the remainder of
/// the program's life. Dropping the returned reference will cause a memory
@@ -1874,7 +1874,7 @@ impl String {
/// ```
#[unstable(feature = "string_leak", issue = "102929")]
#[inline]
- pub fn leak(self) -> &'static mut str {
+ pub fn leak<'a>(self) -> &'a mut str {
let slice = self.vec.leak();
unsafe { from_utf8_unchecked_mut(slice) }
}
@@ -2247,8 +2247,7 @@ impl_eq! { Cow<'a, str>, &'b str }
impl_eq! { Cow<'a, str>, String }
#[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
-impl const Default for String {
+impl Default for String {
/// Creates an empty `String`.
#[inline]
fn default() -> String {
@@ -2528,6 +2527,15 @@ impl<T: fmt::Display + ?Sized> ToString for T {
}
#[cfg(not(no_global_oom_handling))]
+#[unstable(feature = "ascii_char", issue = "110998")]
+impl ToString for core::ascii::Char {
+ #[inline]
+ fn to_string(&self) -> String {
+ self.as_str().to_owned()
+ }
+}
+
+#[cfg(not(no_global_oom_handling))]
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
impl ToString for char {
#[inline]
@@ -2615,6 +2623,15 @@ impl ToString for String {
}
}
+#[cfg(not(no_global_oom_handling))]
+#[stable(feature = "fmt_arguments_to_string_specialization", since = "1.71.0")]
+impl ToString for fmt::Arguments<'_> {
+ #[inline]
+ fn to_string(&self) -> String {
+ crate::fmt::format(*self)
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<str> for String {
#[inline]
@@ -2733,7 +2750,7 @@ impl<'a> From<Cow<'a, str>> for String {
/// ```
/// # use std::borrow::Cow;
/// // If the string is not owned...
- /// let cow: Cow<str> = Cow::Borrowed("eggplant");
+ /// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
/// // It will allocate on the heap and copy the string.
/// let owned: String = String::from(cow);
/// assert_eq!(&owned[..], "eggplant");