]> git.lizzy.rs Git - rust.git/commitdiff
Box::leak - relaxed constraints wrt. lifetimes
authorMazdak <twingoow@gmail.com>
Thu, 9 Nov 2017 22:25:32 +0000 (23:25 +0100)
committerMazdak <twingoow@gmail.com>
Thu, 9 Nov 2017 22:25:32 +0000 (23:25 +0100)
src/liballoc/boxed.rs

index ccaa4d497d45c7cfb40ce900204f9acea62841be..58e5c4d66e4c2316b92df915199e236e78721aee 100644 (file)
@@ -390,7 +390,7 @@ pub fn into_unique(b: Box<T>) -> Unique<T> {
     ///
     /// fn main() {
     ///     let x = Box::new(41);
-    ///     let static_ref = Box::leak(x);
+    ///     let static_ref: &'static mut usize = Box::leak(x);
     ///     *static_ref += 1;
     ///     assert_eq!(*static_ref, 42);
     /// }
@@ -411,7 +411,7 @@ pub fn into_unique(b: Box<T>) -> Unique<T> {
     #[unstable(feature = "box_leak", reason = "needs an FCP to stabilize",
                issue = "0")]
     #[inline]
-    pub fn leak(b: Box<T>) -> &'static mut T {
+    pub fn leak<'a, T: 'a>(b: Box<T>) -> &'a mut T {
         unsafe { &mut *Box::into_raw(b) }
     }
 }