Skip to content

Commit 5ef872f

Browse files
committed
Auto merge of #74605 - rust-lang:vec-leak, r=Amanieu
Stabilize Vec::leak as a method Closes #62195 The signature is changed to a method rather than an associated function: ```diff -pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T] +pub fn leak<'a>(self) -> &'a mut [T] ``` 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.
2 parents 05762e3 + 7d759f5 commit 5ef872f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

library/alloc/src/vec.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1510,20 +1510,18 @@ impl<T> Vec<T> {
15101510
/// Simple usage:
15111511
///
15121512
/// ```
1513-
/// #![feature(vec_leak)]
1514-
///
15151513
/// let x = vec![1, 2, 3];
1516-
/// let static_ref: &'static mut [usize] = Vec::leak(x);
1514+
/// let static_ref: &'static mut [usize] = x.leak();
15171515
/// static_ref[0] += 1;
15181516
/// assert_eq!(static_ref, &[2, 2, 3]);
15191517
/// ```
1520-
#[unstable(feature = "vec_leak", issue = "62195")]
1518+
#[stable(feature = "vec_leak", since = "1.47.0")]
15211519
#[inline]
1522-
pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T]
1520+
pub fn leak<'a>(self) -> &'a mut [T]
15231521
where
15241522
T: 'a, // Technically not needed, but kept to be explicit.
15251523
{
1526-
Box::leak(vec.into_boxed_slice())
1524+
Box::leak(self.into_boxed_slice())
15271525
}
15281526
}
15291527

0 commit comments

Comments
 (0)