Skip to content

Commit 55fc352

Browse files
committed
remove InPlaceIterable marker from Peekable due to unsoundness
The unsoundness is not in Peekable per se, it rather is due to the interaction between Peekable being able to hold an extra item and vec::IntoIter's clone implementation shortening the allocation. An alternative solution would be to change IntoIter's clone implementation to keep enough spare capacity available.
1 parent a88f105 commit 55fc352

File tree

3 files changed

+1
-6
lines changed

3 files changed

+1
-6
lines changed

alloc/benches/vec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ fn bench_in_place_recycle(b: &mut Bencher) {
468468
.enumerate()
469469
.map(|(idx, e)| idx.wrapping_add(e))
470470
.fuse()
471-
.peekable()
472471
.collect::<Vec<usize>>(),
473472
);
474473
});

alloc/tests/vec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ fn test_from_iter_specialization_with_iterator_adapters() {
10021002
.zip(std::iter::repeat(1usize))
10031003
.map(|(a, b)| a + b)
10041004
.map_while(Option::Some)
1005-
.peekable()
10061005
.skip(1)
10071006
.map(|e| if e != usize::MAX { Ok(std::num::NonZeroUsize::new(e)) } else { Err(()) });
10081007
assert_in_place_trait(&iter);

core/src/iter/adapters/peekable.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen};
1+
use crate::iter::{adapters::SourceIter, FusedIterator, TrustedLen};
22
use crate::ops::{ControlFlow, Try};
33

44
/// An iterator with a `peek()` that returns an optional reference to the next
@@ -356,6 +356,3 @@ where
356356
unsafe { SourceIter::as_inner(&mut self.iter) }
357357
}
358358
}
359-
360-
#[unstable(issue = "none", feature = "inplace_iteration")]
361-
unsafe impl<I: InPlaceIterable> InPlaceIterable for Peekable<I> {}

0 commit comments

Comments
 (0)