Skip to content

Commit

Permalink
Auto merge of #52189 - cuviper:static-box-leak, r=bluss
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bors committed Jul 24, 2018
2 parents a2af866 + 6aeeda7 commit a1e6bcb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ impl<T: ?Sized> Box<T> {
}

/// Consumes and leaks the `Box`, returning a mutable reference,
/// `&'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`.
///
/// This function is mainly useful for data that lives for the remainder of
/// the program's life. Dropping the returned reference will cause a memory
Expand Down

0 comments on commit a1e6bcb

Please sign in to comment.