about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrank Steffahn <frank.steffahn@stu.uni-kiel.de>2021-07-01 19:12:13 +0200
committerFrank Steffahn <frank.steffahn@stu.uni-kiel.de>2021-07-28 14:33:36 +0200
commit89583e98e8b79c62ec70d791c9d4453decce1b5b (patch)
tree5191ff12a14af7fb36e27aeb5faf84f6de387398
parent9ff421da992d6612eb43fb58014f83ce15168146 (diff)
downloadrust-89583e98e8b79c62ec70d791c9d4453decce1b5b.tar.gz
rust-89583e98e8b79c62ec70d791c9d4453decce1b5b.zip
Make `SpecInPlaceCollect` use `TrustedRandomAccessNoCoerce`
-rw-r--r--library/alloc/src/vec/source_iter_marker.rs6
-rw-r--r--library/core/src/iter/adapters/zip.rs3
2 files changed, 7 insertions, 2 deletions
diff --git a/library/alloc/src/vec/source_iter_marker.rs b/library/alloc/src/vec/source_iter_marker.rs
index d814d4ae355..4c06c044e1a 100644
--- a/library/alloc/src/vec/source_iter_marker.rs
+++ b/library/alloc/src/vec/source_iter_marker.rs
@@ -1,4 +1,4 @@
-use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccess};
+use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
 use core::mem::{self, ManuallyDrop};
 use core::ptr::{self};
 
@@ -101,6 +101,8 @@ fn write_in_place_with_drop<T>(
 trait SpecInPlaceCollect<T, I>: Iterator<Item = T> {
     /// Collects an iterator (`self`) into the destination buffer (`dst`) and returns the number of items
     /// collected. `end` is the last writable element of the allocation and used for bounds checks.
+    // FIXME: Clarify safety conditions. Iterator must not be coerced to a subtype
+    // after this call due to potential use of [`TrustedRandomAccessNoCoerce`].
     fn collect_in_place(&mut self, dst: *mut T, end: *const T) -> usize;
 }
 
@@ -124,7 +126,7 @@ where
 
 impl<T, I> SpecInPlaceCollect<T, I> for I
 where
-    I: Iterator<Item = T> + TrustedRandomAccess,
+    I: Iterator<Item = T> + TrustedRandomAccessNoCoerce,
 {
     #[inline]
     fn collect_in_place(&mut self, dst_buf: *mut T, end: *const T) -> usize {
diff --git a/library/core/src/iter/adapters/zip.rs b/library/core/src/iter/adapters/zip.rs
index 8a7f6bf9255..0c62ee294fa 100644
--- a/library/core/src/iter/adapters/zip.rs
+++ b/library/core/src/iter/adapters/zip.rs
@@ -514,6 +514,9 @@ impl<A: Debug + TrustedRandomAccessNoCoerce, B: Debug + TrustedRandomAccessNoCoe
 ///   `self.__iterator_get_unchecked(idx)`, assuming that the required traits are implemented.
 /// * It must also be safe to drop `self` after calling `self.__iterator_get_unchecked(idx)`.
 /// * If `T` is a subtype of `Self`, then it must be safe to coerce `self` to `T`.
+//
+// FIXME: Clarify interaction with SourceIter/InPlaceIterable. Calling `SouceIter::as_inner`
+// after `__iterator_get_unchecked` is supposed to be allowed.
 #[doc(hidden)]
 #[unstable(feature = "trusted_random_access", issue = "none")]
 #[rustc_specialization_trait]