Skip to content

Commit 586b51a

Browse files
the8472Mark-Simulacrum
authored andcommitted
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 5a2dbd0 commit 586b51a

File tree

3 files changed

+1
-6
lines changed

3 files changed

+1
-6
lines changed

library/alloc/benches/vec.rs

-1
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
});

library/alloc/tests/vec.rs

-1
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);

library/core/src/iter/adapters/peekable.rs

+1-4
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::Try;
33

44
/// An iterator with a `peek()` that returns an optional reference to the next
@@ -333,6 +333,3 @@ where
333333
unsafe { SourceIter::as_inner(&mut self.iter) }
334334
}
335335
}
336-
337-
#[unstable(issue = "none", feature = "inplace_iteration")]
338-
unsafe impl<I: InPlaceIterable> InPlaceIterable for Peekable<I> {}

0 commit comments

Comments
 (0)