Skip to content

Commit 4f44d62

Browse files
committed
Put fn in the right place.
1 parent f81cd87 commit 4f44d62

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

library/alloc/src/string.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,35 @@ impl String {
18491849
let slice = self.vec.into_boxed_slice();
18501850
unsafe { from_boxed_utf8_unchecked(slice) }
18511851
}
1852+
1853+
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
1854+
/// `&'a mut str`.
1855+
///
1856+
/// This is mainly useful for data that lives for the remainder of
1857+
/// the program's life. Dropping the returned reference will cause a memory
1858+
/// leak.
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+
///
1864+
/// # Examples
1865+
///
1866+
/// Simple usage:
1867+
///
1868+
/// ```
1869+
/// #![feature(string_leak)]
1870+
///
1871+
/// let x = String::from("bucket");
1872+
/// let static_ref: &'static mut str = x.leak();
1873+
/// assert_eq!(static_ref, "bucket");
1874+
/// ```
1875+
#[unstable(feature = "string_leak", issue = "102929")]
1876+
#[inline]
1877+
pub fn leak(self) -> &'static mut str {
1878+
let slice = self.vec.leak();
1879+
unsafe { from_utf8_unchecked_mut(slice) }
1880+
}
18521881
}
18531882

18541883
impl FromUtf8Error {
@@ -2691,35 +2720,6 @@ impl From<String> for Box<str> {
26912720
fn from(s: String) -> Box<str> {
26922721
s.into_boxed_str()
26932722
}
2694-
2695-
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
2696-
/// `&'a mut str`.
2697-
///
2698-
/// This is mainly useful for data that lives for the remainder of
2699-
/// the program's life. Dropping the returned reference will cause a memory
2700-
/// leak.
2701-
///
2702-
/// It does not reallocate or shrink the `String`,
2703-
/// so the leaked allocation may include unused capacity that is not part
2704-
/// of the returned slice.
2705-
///
2706-
/// # Examples
2707-
///
2708-
/// Simple usage:
2709-
///
2710-
/// ```
2711-
/// #![feature(string_leak)]
2712-
///
2713-
/// let x = String::from("bucket");
2714-
/// let static_ref: &'static mut str = x.leak();
2715-
/// assert_eq!(static_ref, "bucket");
2716-
/// ```
2717-
#[unstable(feature = "string_leak", issue = "102929")]
2718-
#[inline]
2719-
pub fn leak(self) -> &'static mut str {
2720-
let slice = self.vec.leak();
2721-
unsafe { from_utf8_unchecked_mut(slice) }
2722-
}
27232723
}
27242724

27252725
#[cfg(not(no_global_oom_handling))]

0 commit comments

Comments
 (0)