Skip to content

doc: Clarify the lifetime returned by Box::leak #52189

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 24, 2018

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Jul 9, 2018

Box::leak mentions that it can return a 'static reference, but it
wasn't immediately clear to me why it doesn't always do so. This is
because of the T: 'a constraint needed to form a valid reference, and
in general we want to be more flexible than requiring T: 'static.
This patch tries to clarify the relationship between T and 'a.

`Box::leak` mentions that it can return a `'static` reference, but it
wasn't immediately clear to me why it doesn't always do so.  This is
because of the `T: 'a` constraint needed to form a valid reference, and
in general we want to be more flexible than requiring `T: 'static`.
This patch tries to clarify the relationship between `T` and `'a`.
@rust-highfive
Copy link
Contributor

r? @bluss

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2018
@TimNN
Copy link
Contributor

TimNN commented Jul 17, 2018

Ping from triage, @bluss: This PR requires your review.

@pietroalbini pietroalbini added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jul 23, 2018
@pietroalbini
Copy link
Member

pietroalbini commented Jul 23, 2018

Ping from triage! This PR needs a review, can @bluss or someone else from @rust-lang/docs review this?

/// `&'a mut T`. Here, the lifetime `'a` may be chosen to be `'static`.
/// `&'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`.
Copy link
Member

Choose a reason for hiding this comment

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

isn't this a must, not a may?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's variant in the lifetime, so it can be shorter. Only T: 'static can leak as &'static mut T, but it can also leak as any other lifetime.

@bluss
Copy link
Member

bluss commented Jul 24, 2018

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Jul 24, 2018

📌 Commit 6aeeda7 has been approved by bluss

@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 Jul 24, 2018
@bors
Copy link
Collaborator

bors commented Jul 24, 2018

⌛ Testing commit 6aeeda7 with merge a1e6bcb...

bors added a commit that referenced this pull request Jul 24, 2018
doc: Clarify the lifetime returned by `Box::leak`

`Box::leak` mentions that it can return a `'static` reference, but it
wasn't immediately clear to me why it doesn't always do so.  This is
because of the `T: 'a` constraint needed to form a valid reference, and
in general we want to be more flexible than requiring `T: 'static`.
This patch tries to clarify the relationship between `T` and `'a`.
@bors
Copy link
Collaborator

bors commented Jul 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: bluss
Pushing a1e6bcb to master...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants