Skip to content

Commit 76a49ef

Browse files
committed
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.
1 parent 8ad7bc3 commit 76a49ef

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/liballoc/vec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1515,17 +1515,17 @@ impl<T> Vec<T> {
15151515
/// #![feature(vec_leak)]
15161516
///
15171517
/// let x = vec![1, 2, 3];
1518-
/// let static_ref: &'static mut [usize] = Vec::leak(x);
1518+
/// let static_ref: &'static mut [usize] = x.leak();
15191519
/// static_ref[0] += 1;
15201520
/// assert_eq!(static_ref, &[2, 2, 3]);
15211521
/// ```
15221522
#[unstable(feature = "vec_leak", issue = "62195")]
15231523
#[inline]
1524-
pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T]
1524+
pub fn leak<'a>(self) -> &'a mut [T]
15251525
where
15261526
T: 'a, // Technically not needed, but kept to be explicit.
15271527
{
1528-
Box::leak(vec.into_boxed_slice())
1528+
Box::leak(self.into_boxed_slice())
15291529
}
15301530
}
15311531

0 commit comments

Comments
 (0)