]> git.lizzy.rs Git - rust.git/commitdiff
Make `Vec::leak` a method instead of an associated function.
authorSimon Sapin <simon.sapin@exyr.org>
Tue, 21 Jul 2020 21:06:23 +0000 (23:06 +0200)
committerSimon Sapin <simon.sapin@exyr.org>
Wed, 29 Jul 2020 08:53:55 +0000 (10:53 +0200)
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

index f5a3d0cd4af87fd89e75bf81d3b38ae5b660df66..3414060a55687739b2cd97119a82cb17adea60ff 100644 (file)
@@ -1513,17 +1513,17 @@ pub fn resize_with<F>(&mut self, new_len: usize, f: F)
     /// #![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<T>) -> &'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())
     }
 }