From d8bcf75206e88e07cabd95b87418fe98c5fa2b95 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 21 Jul 2020 23:06:23 +0200 Subject: [PATCH 1/2] Make `Vec::leak` a method instead of an associated function. The reason for `Box::leak` not to be a method (`Deref` to an arbitrary `T` which might have its own, different `leak` method) does not apply. --- library/alloc/src/vec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index f5a3d0cd4af87..3414060a55687 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1513,17 +1513,17 @@ impl Vec { /// #![feature(vec_leak)] /// /// let x = vec![1, 2, 3]; - /// let static_ref: &'static mut [usize] = Vec::leak(x); + /// let static_ref: &'static mut [usize] = x.leak(); /// static_ref[0] += 1; /// assert_eq!(static_ref, &[2, 2, 3]); /// ``` #[unstable(feature = "vec_leak", issue = "62195")] #[inline] - pub fn leak<'a>(vec: Vec) -> &'a mut [T] + pub fn leak<'a>(self) -> &'a mut [T] where T: 'a, // Technically not needed, but kept to be explicit. { - Box::leak(vec.into_boxed_slice()) + Box::leak(self.into_boxed_slice()) } } From 7d759f539f363125511f1edd9ad30934367f409b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 21 Jul 2020 23:08:27 +0200 Subject: [PATCH 2/2] Stabilize `Vec::leak` --- library/alloc/src/vec.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 3414060a55687..9eb37bf473fed 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1510,14 +1510,12 @@ impl Vec { /// Simple usage: /// /// ``` - /// #![feature(vec_leak)] - /// /// let x = vec![1, 2, 3]; /// let static_ref: &'static mut [usize] = x.leak(); /// static_ref[0] += 1; /// assert_eq!(static_ref, &[2, 2, 3]); /// ``` - #[unstable(feature = "vec_leak", issue = "62195")] + #[stable(feature = "vec_leak", since = "1.47.0")] #[inline] pub fn leak<'a>(self) -> &'a mut [T] where