Skip to content

Commit 6648134

Browse files
committed
Apply review feedback; Fix no_global_oom_handling build
1 parent 58e60ac commit 6648134

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
590590
VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) }
591591
}
592592

593+
/// Creates a `VecDeque` from a raw allocation, when the initialized
594+
/// part of that allocation forms a *contiguous* subslice thereof.
595+
///
593596
/// For use by `vec::IntoIter::into_vecdeque`
594597
///
595598
/// # Safety

library/alloc/src/vec/into_iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(not(no_global_oom_handling))]
22
use super::AsVecIntoIter;
33
use crate::alloc::{Allocator, Global};
4+
#[cfg(not(no_global_oom_handling))]
45
use crate::collections::VecDeque;
56
use crate::raw_vec::RawVec;
67
use core::array;
@@ -134,6 +135,7 @@ impl<T, A: Allocator> IntoIter<T, A> {
134135
self.ptr = self.end;
135136
}
136137

138+
#[cfg(not(no_global_oom_handling))]
137139
#[inline]
138140
pub(crate) fn into_vecdeque(self) -> VecDeque<T, A> {
139141
// Keep our `Drop` impl from dropping the elements and the allocator

library/alloc/tests/vec_deque.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,22 +1741,32 @@ fn test_resize_keeps_reserved_space_from_item() {
17411741
fn test_collect_from_into_iter_keeps_allocation() {
17421742
let mut v = Vec::with_capacity(13);
17431743
v.extend(0..7);
1744-
check(v.into_iter());
1744+
check(v.as_ptr(), v.last().unwrap(), v.into_iter());
17451745

17461746
let mut v = VecDeque::with_capacity(13);
17471747
v.extend(0..7);
1748-
check(v.into_iter());
1748+
check(&v[0], &v[v.len() - 1], v.into_iter());
17491749

1750-
fn check(mut it: impl Iterator<Item = i32>) {
1750+
fn check(buf: *const i32, last: *const i32, mut it: impl Iterator<Item = i32>) {
17511751
assert_eq!(it.next(), Some(0));
17521752
assert_eq!(it.next(), Some(1));
1753+
17531754
let mut v: VecDeque<i32> = it.collect();
17541755
assert_eq!(v.capacity(), 13);
1756+
assert_eq!(v.as_slices().0.as_ptr(), buf.wrapping_add(2));
1757+
assert_eq!(&v[v.len() - 1] as *const _, last);
1758+
17551759
assert_eq!(v.as_slices(), ([2, 3, 4, 5, 6].as_slice(), [].as_slice()));
17561760
v.push_front(7);
17571761
assert_eq!(v.as_slices(), ([7, 2, 3, 4, 5, 6].as_slice(), [].as_slice()));
17581762
v.push_front(8);
17591763
assert_eq!(v.as_slices(), ([8, 7, 2, 3, 4, 5, 6].as_slice(), [].as_slice()));
1764+
1765+
// Now that we've adding thing in place of the two that we removed from
1766+
// the front of the iterator, we're back to matching the buffer pointer.
1767+
assert_eq!(v.as_slices().0.as_ptr(), buf);
1768+
assert_eq!(&v[v.len() - 1] as *const _, last);
1769+
17601770
v.push_front(9);
17611771
assert_eq!(v.as_slices(), ([9].as_slice(), [8, 7, 2, 3, 4, 5, 6].as_slice()));
17621772
assert_eq!(v.capacity(), 13);

0 commit comments

Comments
 (0)