From 89583e98e8b79c62ec70d791c9d4453decce1b5b Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 1 Jul 2021 19:12:13 +0200 Subject: [PATCH] Make `SpecInPlaceCollect` use `TrustedRandomAccessNoCoerce` --- library/alloc/src/vec/source_iter_marker.rs | 6 ++++-- library/core/src/iter/adapters/zip.rs | 3 +++ 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( trait SpecInPlaceCollect: Iterator { /// 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 SpecInPlaceCollect for I where - I: Iterator + TrustedRandomAccess, + I: Iterator + 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