Skip to content

Commit 622db98

Browse files
CoAlloc: Added CO_ALLOC_PREF to two Guard structs inside vec_deque::into_iter. Tidy.
1 parent d57e141 commit 622db98

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

library/alloc/src/collections/binary_heap/tests.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::boxed::Box;
3-
use crate::{CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO};
43
use crate::testing::crash_test::{CrashTestDummy, Panic};
4+
use crate::{CO_ALLOC_PREF_META_NO, CO_ALLOC_PREF_META_YES};
55
use core::mem;
66
use std::iter::TrustedLen;
77
use std::panic::{catch_unwind, AssertUnwindSafe};
@@ -449,10 +449,14 @@ fn test_extend_specialization() {
449449

450450
#[allow(dead_code)]
451451
fn assert_covariance() {
452-
fn drain<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_NO!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_NO!()}> {
452+
fn drain<'new>(
453+
d: Drain<'static, &'static str, { CO_ALLOC_PREF_META_NO!() }>,
454+
) -> Drain<'new, &'new str, { CO_ALLOC_PREF_META_NO!() }> {
453455
d
454456
}
455-
fn drain_co<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_YES!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_YES!()}> {
457+
fn drain_co<'new>(
458+
d: Drain<'static, &'static str, { CO_ALLOC_PREF_META_YES!() }>,
459+
) -> Drain<'new, &'new str, { CO_ALLOC_PREF_META_YES!() }> {
456460
d
457461
}
458462
}

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use core::iter::{FusedIterator, TrustedLen};
2-
use core::{alloc, array, fmt, mem::MaybeUninit, ops::Try, ptr};
31
use crate::co_alloc::CoAllocPref;
2+
use core::iter::{FusedIterator, TrustedLen};
3+
use core::{array, fmt, mem::MaybeUninit, ops::Try, ptr};
44

55
use crate::alloc::{Allocator, Global};
66

@@ -93,13 +93,19 @@ where
9393
F: FnMut(B, Self::Item) -> R,
9494
R: Try<Output = B>,
9595
{
96-
struct Guard<'a, T, A: Allocator> {
97-
deque: &'a mut VecDeque<T, A>,
96+
struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>
97+
where
98+
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
99+
{
100+
deque: &'a mut VecDeque<T, A, CO_ALLOC_PREF>,
98101
// `consumed <= deque.len` always holds.
99102
consumed: usize,
100103
}
101104

102-
impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> {
105+
impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF>
106+
where
107+
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
108+
{
103109
fn drop(&mut self) {
104110
self.deque.len -= self.consumed;
105111
self.deque.head = self.deque.to_physical_idx(self.consumed);
@@ -221,13 +227,19 @@ where
221227
F: FnMut(B, Self::Item) -> R,
222228
R: Try<Output = B>,
223229
{
224-
struct Guard<'a, T, A: Allocator> {
225-
deque: &'a mut VecDeque<T, A>,
230+
struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>
231+
where
232+
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
233+
{
234+
deque: &'a mut VecDeque<T, A, CO_ALLOC_PREF>,
226235
// `consumed <= deque.len` always holds.
227236
consumed: usize,
228237
}
229238

230-
impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> {
239+
impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF>
240+
where
241+
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
242+
{
231243
fn drop(&mut self) {
232244
self.deque.len -= self.consumed;
233245
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,8 +2844,7 @@ where
28442844

28452845
#[stable(feature = "rust1", since = "1.0.0")]
28462846
#[allow(unused_braces)]
2847-
impl<T> FromIterator<T> for VecDeque<T>
2848-
{
2847+
impl<T> FromIterator<T> for VecDeque<T> {
28492848
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> VecDeque<T> {
28502849
SpecFromIterCo::spec_from_iter_co(iter.into_iter())
28512850
}

library/alloc/src/slice.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ pub(crate) mod hack {
103103
// `vec!` macro mostly and causes perf regression. See #71204 for
104104
// discussion and perf results.
105105
#[allow(unused_braces)]
106-
pub fn into_vec<T, A: Allocator>(
107-
b: Box<[T], A>,
108-
) -> Vec<T, A>
106+
pub fn into_vec<T, A: Allocator>(b: Box<[T], A>) -> Vec<T, A>
109107
where
110108
[(); { crate::meta_num_slots_default!(A) }]:,
111109
{
112-
into_vec_co::<T, A, {crate::CO_ALLOC_PREF_META_DEFAULT!()}>(b)
110+
into_vec_co::<T, A, { crate::CO_ALLOC_PREF_META_DEFAULT!() }>(b)
113111
}
114112

115113
#[allow(unused_braces)]

0 commit comments

Comments
 (0)