@@ -1853,28 +1853,30 @@ impl String {
1853
1853
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
1854
1854
/// `&'a mut str`.
1855
1855
///
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
1857
1857
/// the program's life. Dropping the returned reference will cause a memory
1858
1858
/// leak.
1859
1859
///
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
+ ///
1860
1864
/// # Examples
1861
1865
///
1862
1866
/// Simple usage:
1863
1867
///
1864
1868
/// ```
1865
1869
/// #![feature(string_leak)]
1866
1870
///
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");
1872
1874
/// ```
1873
1875
#[ cfg( not( no_global_oom_handling) ) ]
1874
1876
#[ unstable( feature = "string_leak" , issue = "102929" ) ]
1875
1877
#[ 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 ( ) ;
1878
1880
unsafe { from_utf8_unchecked_mut ( slice) }
1879
1881
}
1880
1882
}
0 commit comments