Skip to content

Commit 61e07f5

Browse files
VecDeque use cases have COOP_PREFERRED
1 parent cede813 commit 61e07f5

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ dependencies = [
303303

304304
[[package]]
305305
name = "cargo"
306-
version = "0.69.0"
306+
version = "0.68.0"
307307
dependencies = [
308308
"anyhow",
309309
"bytesize",

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ use super::VecDeque;
1717
pub struct IntoIter<
1818
T,
1919
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
20+
const COOP_PREFERRED: bool = true
2021
>
21-
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
22-
inner: VecDeque<T, A>,
22+
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
23+
inner: VecDeque<T, A, COOP_PREFERRED>,
2324
}
2425

25-
impl<T, A: Allocator> IntoIter<T, A>
26+
impl<T, A: Allocator, const COOP_PREFERRED: bool> IntoIter<T, A, COOP_PREFERRED>
2627
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
27-
pub(super) fn new(inner: VecDeque<T, A>) -> Self {
28+
pub(super) fn new(inner: VecDeque<T, A, COOP_PREFERRED>) -> Self {
2829
IntoIter { inner }
2930
}
3031

31-
pub(super) fn into_vecdeque(self) -> VecDeque<T, A> {
32+
pub(super) fn into_vecdeque(self) -> VecDeque<T, A, COOP_PREFERRED> {
3233
self.inner
3334
}
3435
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
153153
}
154154

155155
#[stable(feature = "rust1", since = "1.0.0")]
156-
impl<T> Default for VecDeque<T> {
156+
impl<T, const COOP_PREFERRED: bool = true> Default for VecDeque<T, Global, COOP_PREFERRED> {
157157
/// Creates an empty deque.
158158
#[inline]
159-
fn default() -> VecDeque<T> {
159+
fn default() -> VecDeque<T, Global, COOP_PREFERRED> {
160160
VecDeque::new()
161161
}
162162
}
@@ -536,7 +536,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
536536
}
537537
}
538538

539-
impl<T> VecDeque<T> {
539+
impl<T, Global, const COOP_PREFERRED: bool> VecDeque<T, Global, COOP_PREFERRED>
540+
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
540541
/// Creates an empty deque.
541542
///
542543
/// # Examples
@@ -550,7 +551,7 @@ impl<T> VecDeque<T> {
550551
#[stable(feature = "rust1", since = "1.0.0")]
551552
#[rustc_const_stable(feature = "const_vec_deque_new", since = "CURRENT_RUSTC_VERSION")]
552553
#[must_use]
553-
pub const fn new() -> VecDeque<T> {
554+
pub const fn new() -> VecDeque<T, Global, COOP_PREFERRED> {
554555
// FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
555556
VecDeque { head: 0, len: 0, buf: RawVec::NEW }
556557
}
@@ -567,7 +568,7 @@ impl<T> VecDeque<T> {
567568
#[inline]
568569
#[stable(feature = "rust1", since = "1.0.0")]
569570
#[must_use]
570-
pub fn with_capacity(capacity: usize) -> VecDeque<T> {
571+
pub fn with_capacity(capacity: usize) -> VecDeque<T, Global, COOP_PREFERRED> {
571572
Self::with_capacity_in(capacity, Global)
572573
}
573574
}
@@ -585,7 +586,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
585586
/// ```
586587
#[inline]
587588
#[unstable(feature = "allocator_api", issue = "32838")]
588-
pub const fn new_in(alloc: A) -> VecDeque<T, A> {
589+
pub const fn new_in(alloc: A) -> VecDeque<T, A, COOP_PREFERRED> {
589590
VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) }
590591
}
591592

@@ -599,7 +600,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
599600
/// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
600601
/// ```
601602
#[unstable(feature = "allocator_api", issue = "32838")]
602-
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
603+
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A, COOP_PREFERRED> {
603604
VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) }
604605
}
605606

@@ -2890,7 +2891,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
28902891
/// assert_eq!(vec, [8, 9, 1, 2, 3, 4]);
28912892
/// assert_eq!(vec.as_ptr(), ptr);
28922893
/// ```
2893-
fn from(mut other: VecDeque<T, A>) -> Self {
2894+
fn from<const _VECDEQUE_COOP_PREFERRED: bool>(mut other: VecDeque<T, A, _VECDEQUE_COOP_PREFERRED>) -> Self {
28942895
other.make_contiguous();
28952896

28962897
unsafe {
@@ -2903,6 +2904,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
29032904
if other.head != 0 {
29042905
ptr::copy(buf.add(other.head), buf, len);
29052906
}
2907+
// @TODO:
29062908
Vec::from_raw_parts_in(buf, len, cap, alloc)
29072909
}
29082910
}

library/std/src/io/impls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ impl<A: Allocator> Write for Vec<u8, A> {
414414

415415
/// Read is implemented for `VecDeque<u8>` by consuming bytes from the front of the `VecDeque`.
416416
#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
417-
impl<A: Allocator> Read for VecDeque<u8, A> {
417+
impl<A: Allocator, const _COOP_PREFERRED: bool> Read for VecDeque<u8, A, _COOP_PREFERRED>
418+
where [(); co_alloc_metadata_num_slots_with_preference::<A>(_COOP_PREFERRED)]: {
418419
/// Fill `buf` with the contents of the "front" slice as returned by
419420
/// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are
420421
/// discontiguous, multiple calls to `read` will be needed to read the entire content.
@@ -438,7 +439,8 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
438439

439440
/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
440441
#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
441-
impl<A: Allocator> Write for VecDeque<u8, A> {
442+
impl<A: Allocator, const _COOP_PREFERRED: bool> Write for VecDeque<u8, A, _COOP_PREFERRED>
443+
where [(); co_alloc_metadata_num_slots_with_preference::<A>(_COOP_PREFERRED)]: {
442444
#[inline]
443445
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
444446
self.extend(buf);

src/doc/nomicon

0 commit comments

Comments
 (0)