about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-24 10:46:21 +0000
committerbors <bors@rust-lang.org>2018-07-24 10:46:21 +0000
commita1e6bcb2085cba3d5e549ba3b175f99487c21639 (patch)
tree51faee9c53a9cf16e2014c6f48a15ec0f14c96a2 /src/liballoc
parenta2af8667b1a5166137510aeb2aaad9945f81db6d (diff)
parent6aeeda714e04ac34205a7b948e5585e00d0fa14d (diff)
downloadrust-a1e6bcb2085cba3d5e549ba3b175f99487c21639.tar.gz
rust-a1e6bcb2085cba3d5e549ba3b175f99487c21639.zip
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`.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 44f15981137..6d3bc6e79b5 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -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