From 19e66953b574154bff777bc44b7d9ce22e197ab6 Mon Sep 17 00:00:00 2001 From: Markus Everling Date: Tue, 29 Nov 2022 22:18:34 +0100 Subject: [PATCH 1/4] fix typo in comment --- library/alloc/src/collections/vec_deque/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 86d77182bccee..0c3d5fe35cb32 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2152,7 +2152,7 @@ impl VecDeque { self.head = tail; } else { - // ´free` is smaller than both `head_len` and `tail_len`. + // `free` is smaller than both `head_len` and `tail_len`. // the general algorithm for this first moves the slices // right next to each other and then uses `slice::rotate` // to rotate them into place: From 327b94a8a82fae1c4a02eb8e277734eee30abad9 Mon Sep 17 00:00:00 2001 From: Markus Everling Date: Tue, 29 Nov 2022 23:10:19 +0100 Subject: [PATCH 2/4] Make `VecDeque::{new,new_in}` `const fn`s --- library/alloc/src/collections/vec_deque/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 0c3d5fe35cb32..eab839e563e9f 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -531,12 +531,13 @@ impl VecDeque { /// /// let deque: VecDeque = 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 = "1.67.0")] #[must_use] - pub fn new() -> VecDeque { - VecDeque::new_in(Global) + pub const fn new() -> VecDeque { + // FIXME: This should just be `VecDeque::new_in(Global)` once that's stable. + VecDeque { head: 0, len: 0, buf: RawVec::NEW } } /// Creates an empty deque with space for at least `capacity` elements. @@ -566,10 +567,9 @@ impl VecDeque { /// /// let deque: VecDeque = VecDeque::new(); /// ``` - // FIXME: This should probably be const #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn new_in(alloc: A) -> VecDeque { + pub const fn new_in(alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) } } From a06f7f84e79ffa1f30c8c0add9310d0655540d91 Mon Sep 17 00:00:00 2001 From: Markus Everling Date: Tue, 29 Nov 2022 23:13:36 +0100 Subject: [PATCH 3/4] Add O(1) `Vec -> VecDeque` conversion guarantee --- library/alloc/src/collections/vec_deque/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index eab839e563e9f..2c8b975ca597a 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2789,9 +2789,9 @@ impl From> for VecDeque { /// [`Vec`]: crate::vec::Vec /// [`VecDeque`]: crate::collections::VecDeque /// - /// In its current implementation, this is a very cheap - /// conversion. This isn't yet a guarantee though, and - /// shouldn't be relied on. + /// This conversion is guaranteed to run in *O*(1) time + /// and to not re-allocate the `Vec`'s buffer or + /// allocate any additional memory. fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } From 82fc73034a5b98795acca5f37a0253d03fb267c4 Mon Sep 17 00:00:00 2001 From: Sp00ph <61327188+Sp00ph@users.noreply.github.com> Date: Wed, 30 Nov 2022 00:03:37 +0100 Subject: [PATCH 4/4] Use `CURRENT_RUSTC_VERSION` placeholder Co-authored-by: scottmcm --- library/alloc/src/collections/vec_deque/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 2c8b975ca597a..858069903af0d 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -533,7 +533,7 @@ impl VecDeque { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.67.0")] + #[rustc_const_stable(feature = "const_vec_deque_new", since = "CURRENT_RUSTC_VERSION")] #[must_use] pub const fn new() -> VecDeque { // FIXME: This should just be `VecDeque::new_in(Global)` once that's stable.