Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation for rust-lang/libs-team#138 #105072

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,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's stable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also slap #[allow_internal_unstable(allocator_api)] onto VecDeque::new instead. Not sure if that's frowned upon though. What does the library team say?

VecDeque { head: 0, len: 0, buf: RawVec::NEW }
}

/// Creates an empty deque with space for at least `capacity` elements.
Expand Down Expand Up @@ -566,10 +567,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// let deque: VecDeque<u32> = VecDeque::new();
/// ```
// FIXME: This should probably be const
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn new_in(alloc: A) -> VecDeque<T, A> {
pub const fn new_in(alloc: A) -> VecDeque<T, A> {
VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) }
}

Expand Down Expand Up @@ -2152,7 +2152,7 @@ impl<T, A: Allocator> VecDeque<T, A> {

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:
Expand Down Expand Up @@ -2789,9 +2789,9 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
/// [`Vec<T>`]: crate::vec::Vec
/// [`VecDeque<T>`]: 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<T, A>) -> 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) } }
Expand Down