From dabb0c6605d2afb96892f7a3dad64b13c934de74 Mon Sep 17 00:00:00 2001 From: Mazdak Date: Thu, 9 Nov 2017 23:25:32 +0100 Subject: [PATCH] Box::leak - relaxed constraints wrt. lifetimes --- src/liballoc/boxed.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index ccaa4d497d4..58e5c4d66e4 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -390,7 +390,7 @@ pub fn into_unique(b: Box) -> Unique { /// /// 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) -> Unique { #[unstable(feature = "box_leak", reason = "needs an FCP to stabilize", issue = "0")] #[inline] - pub fn leak(b: Box) -> &'static mut T { + pub fn leak<'a, T: 'a>(b: Box) -> &'a mut T { unsafe { &mut *Box::into_raw(b) } } } -- 2.44.0