Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an unbounded lifetime in String::leak. #111656

Merged
merged 1 commit into from
May 27, 2023

Conversation

finnbear
Copy link
Contributor

@finnbear finnbear commented May 16, 2023

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:

ACP: rust-lang/libs-team#109

@rustbot
Copy link
Collaborator

rustbot commented May 16, 2023

r? @m-ou-se

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 16, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@finnbear
Copy link
Contributor Author

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2023
Copy link
Member

@est31 est31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@est31 est31 mentioned this pull request May 27, 2023
@Amanieu
Copy link
Member

Amanieu commented May 27, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 27, 2023

📌 Commit f0c9c1e has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 27, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 27, 2023
…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
@bors bors merged commit 5a4c04c into rust-lang:master May 27, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants