Use an unbounded lifetime in String::leak.#111656
Conversation
|
r? @m-ou-se (rustbot has picked a reviewer for you, use r? to override) |
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
|
@rustbot label +T-libs-api -T-libs |
est31
left a comment
There was a problem hiding this comment.
Maybe it could be pointed out that the lifetime can be 'static as well? This is explicitly mentioned for Box::leak and also for Vec::leak:
Consumes and leaks the Vec, returning a mutable reference to the contents, &'a mut [T]. Note that the type T must outlive the chosen lifetime 'a. If the type has only static references, or none at all, then this may be chosen to be 'static.
At least when I first encountered these functions I wondered if I can set the lifetime to 'static and the docs greatly helped. There is a static lifetime in the example below though, so maybe it's not that needed. IDK.
|
@bors r+ rollup |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#108630 (Fix docs for `alloc::realloc`) - rust-lang#109084 (rustc driver: Remove argument 0 before at-expansion to prevent ICE) - rust-lang#111181 (fix(parse): return unpected when current token is EOF) - rust-lang#111656 (Use an unbounded lifetime in `String::leak`.) - rust-lang#111946 (rustdoc: Add `ItemTemplate` trait and related functions to avoid repetitively wrapping existing functions) - rust-lang#112018 (Clean up usage of `cx.tcx` when `tcx` is already set into a variable) r? `@ghost` `@rustbot` modify labels: rollup
Using
'ainstead of'staticis predicted to make the process of makingStringgeneric over an allocator easier/less of a breaking change.See:
ACP: rust-lang/libs-team#109