diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-06-14 18:10:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-14 18:10:28 +0200 |
| commit | b8f71eaf0195be2a42e054e8adf7a8f967b829c1 (patch) | |
| tree | 7d0691e34618cf9ff55b2252f13f74eb5e155d05 /library/alloc/src/string.rs | |
| parent | d54bb505d01ec8be7d549892db8500f37040cfe4 (diff) | |
| parent | 3ab0d90b7ec726c79893658b510ec955c79b1b79 (diff) | |
| download | rust-b8f71eaf0195be2a42e054e8adf7a8f967b829c1.tar.gz rust-b8f71eaf0195be2a42e054e8adf7a8f967b829c1.zip | |
Rollup merge of #109814 - est31:stabilize_string_leak, r=Amanieu
Stabilize String::leak
Stabilizes the following API:
```Rust
impl String {
pub fn leak(self) -> &'static mut str;
}
```
closes #102929
blocked by having an FCP for stabilization.
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 59e3f887b52..1c6815fa941 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1853,26 +1853,27 @@ impl String { /// Consumes and leaks the `String`, returning a mutable reference to the contents, /// `&'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 - /// leak. + /// The caller has free choice over the returned lifetime, including `'static`. Indeed, + /// this function is ideally used for data that lives for the remainder of the program's life, + /// as dropping the returned reference will cause a memory leak. /// /// It does not reallocate or shrink the `String`, /// so the leaked allocation may include unused capacity that is not part - /// of the returned slice. + /// of the returned slice. If you don't want that, call [`into_boxed_str`], + /// and then [`Box::leak`]. + /// + /// [`into_boxed_str`]: Self::into_boxed_str /// /// # Examples /// /// Simple usage: /// /// ``` - /// #![feature(string_leak)] - /// /// let x = String::from("bucket"); /// let static_ref: &'static mut str = x.leak(); /// assert_eq!(static_ref, "bucket"); /// ``` - #[unstable(feature = "string_leak", issue = "102929")] + #[stable(feature = "string_leak", since = "CURRENT_RUSTC_VERSION")] #[inline] pub fn leak<'a>(self) -> &'a mut str { let slice = self.vec.leak(); |
