Skip to content

Commit 3e882e2

Browse files
committed
Revisions.
1 parent 78eaa5e commit 3e882e2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

library/alloc/src/string.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1853,28 +1853,30 @@ impl String {
18531853
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
18541854
/// `&'a mut str`.
18551855
///
1856-
/// This function is mainly useful for data that lives for the remainder of
1856+
/// This is mainly useful for data that lives for the remainder of
18571857
/// the program's life. Dropping the returned reference will cause a memory
18581858
/// leak.
18591859
///
1860+
/// It does not reallocate or shrink the `String`,
1861+
/// so the leaked allocation may include unused capacity that is not part
1862+
/// of the returned slice.
1863+
///
18601864
/// # Examples
18611865
///
18621866
/// Simple usage:
18631867
///
18641868
/// ```
18651869
/// #![feature(string_leak)]
18661870
///
1867-
/// pub fn main() {
1868-
/// let x = String::from("bucket");
1869-
/// let static_ref: &'static mut str = x.leak();
1870-
/// assert_eq!(static_ref, "bucket");
1871-
/// }
1871+
/// let x = String::from("bucket");
1872+
/// let static_ref: &'static mut str = x.leak();
1873+
/// assert_eq!(static_ref, "bucket");
18721874
/// ```
18731875
#[cfg(not(no_global_oom_handling))]
18741876
#[unstable(feature = "string_leak", issue = "102929")]
18751877
#[inline]
1876-
pub fn leak<'a>(self) -> &'a mut str {
1877-
let slice = self.into_bytes().leak();
1878+
pub fn leak(self) -> &'static mut str {
1879+
let slice = self.vec.leak();
18781880
unsafe { from_utf8_unchecked_mut(slice) }
18791881
}
18801882
}

0 commit comments

Comments
 (0)