Skip to content

Commit d8bcf75

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 10c3757 commit d8bcf75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/alloc/src/vec.rs

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

0 commit comments

Comments
 (0)