Skip to content

Commit a1e6bcb

Browse files
committed
Auto merge of #52189 - cuviper:static-box-leak, r=bluss
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`.
2 parents a2af866 + 6aeeda7 commit a1e6bcb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/liballoc/boxed.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ impl<T: ?Sized> Box<T> {
194194
}
195195

196196
/// Consumes and leaks the `Box`, returning a mutable reference,
197-
/// `&'a mut T`. Here, the lifetime `'a` may be chosen to be `'static`.
197+
/// `&'a mut T`. Note that the type `T` must outlive the chosen lifetime
198+
/// `'a`. If the type has only static references, or none at all, then this
199+
/// may be chosen to be `'static`.
198200
///
199201
/// This function is mainly useful for data that lives for the remainder of
200202
/// the program's life. Dropping the returned reference will cause a memory

0 commit comments

Comments
 (0)