Skip to content

Commit

Permalink
Rollup merge of #111656 - finnbear:string_leak_unbounded_lifetime, r=…
Browse files Browse the repository at this point in the history
…Amanieu

Use an unbounded lifetime in `String::leak`.

Using `'a` instead of `'static` is predicted to make the process of making `String` generic over an allocator easier/less of a breaking change.

See:
- rust-lang/rust#109814 (comment)
- rust-lang/rust#109814 (comment)

ACP: rust-lang/libs-team#109
  • Loading branch information
matthiaskrgr authored May 27, 2023
2 parents e4d3d1d + a5a2eba commit eb7c1b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
}
Expand Down

0 comments on commit eb7c1b5

Please sign in to comment.