]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #105127 - Sp00ph:const_new, r=dtolnay
authorbors <bors@rust-lang.org>
Tue, 20 Dec 2022 20:25:42 +0000 (20:25 +0000)
committerbors <bors@rust-lang.org>
Tue, 20 Dec 2022 20:25:42 +0000 (20:25 +0000)
Make `VecDeque::new` const

(See #105072)

library/alloc/src/collections/vec_deque/mod.rs

index be615b70ced9cfffd9f0ffd2c61752a61410538a..c955db46d29fe11dae1fe3f2d38deed47dbe00ea 100644 (file)
@@ -535,12 +535,13 @@ impl<T> VecDeque<T> {
     ///
     /// let deque: VecDeque<u32> = VecDeque::new();
     /// ```
-    // FIXME: This should probably be const
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[rustc_const_stable(feature = "const_vec_deque_new", since = "CURRENT_RUSTC_VERSION")]
     #[must_use]
-    pub fn new() -> VecDeque<T> {
-        VecDeque::new_in(Global)
+    pub const fn new() -> VecDeque<T> {
+        // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
+        VecDeque { head: 0, len: 0, buf: RawVec::NEW }
     }
 
     /// Creates an empty deque with space for at least `capacity` elements.