-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
doc: Clarify the lifetime returned by Box::leak
#52189
Conversation
`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`.
r? @bluss (rust_highfive has picked a reviewer for you, use r? to override) |
Ping from triage, @bluss: This PR requires your review. |
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`. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@bors r+ Thanks! |
📌 Commit 6aeeda7 has been approved by |
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`.
☀️ Test successful - status-appveyor, status-travis |
Box::leak
mentions that it can return a'static
reference, but itwasn'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, andin general we want to be more flexible than requiring
T: 'static
.This patch tries to clarify the relationship between
T
and'a
.