Skip to content

Commit cdddb4c

Browse files
committed
Make SpecInPlaceCollect use TrustedRandomAccessNoCoerce
1 parent a9f06bb commit cdddb4c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

library/alloc/src/vec/source_iter_marker.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccess};
1+
use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
22
use core::mem::{self, ManuallyDrop};
33
use core::ptr::{self};
44

@@ -101,6 +101,8 @@ fn write_in_place_with_drop<T>(
101101
trait SpecInPlaceCollect<T, I>: Iterator<Item = T> {
102102
/// Collects an iterator (`self`) into the destination buffer (`dst`) and returns the number of items
103103
/// collected. `end` is the last writable element of the allocation and used for bounds checks.
104+
// FIXME: Clarify safety conditions. Iterator must not be coerced to a subtype
105+
// after this call due to potential use of [`TrustedRandomAccessNoCoerce`].
104106
fn collect_in_place(&mut self, dst: *mut T, end: *const T) -> usize;
105107
}
106108

@@ -124,7 +126,7 @@ where
124126

125127
impl<T, I> SpecInPlaceCollect<T, I> for I
126128
where
127-
I: Iterator<Item = T> + TrustedRandomAccess,
129+
I: Iterator<Item = T> + TrustedRandomAccessNoCoerce,
128130
{
129131
#[inline]
130132
fn collect_in_place(&mut self, dst_buf: *mut T, end: *const T) -> usize {

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

+3
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ impl<A: Debug + TrustedRandomAccessNoCoerce, B: Debug + TrustedRandomAccessNoCoe
514514
/// `self.__iterator_get_unchecked(idx)`, assuming that the required traits are implemented.
515515
/// * It must also be safe to drop `self` after calling `self.__iterator_get_unchecked(idx)`.
516516
/// * If `T` is a subtype of `Self`, then it must be safe to coerce `self` to `T`.
517+
//
518+
// FIXME: Clarify interaction with SourceIter/InPlaceIterable. Calling `SouceIter::as_inner`
519+
// after `__iterator_get_unchecked` is supposed to be allowed.
517520
#[doc(hidden)]
518521
#[unstable(feature = "trusted_random_access", issue = "none")]
519522
#[rustc_specialization_trait]

0 commit comments

Comments
 (0)