6060//! # O(1) collect
6161//!
6262//! The main iteration itself is further specialized when the iterator implements
63- //! [`TrustedRandomAccessNoCoerce `] to let the optimizer see that it is a counted loop with a single
63+ //! [`TrustedRandomAccess `] to let the optimizer see that it is a counted loop with a single
6464//! [induction variable]. This can turn some iterators into a noop, i.e. it reduces them from O(n) to
6565//! O(1). This particular optimization is quite fickle and doesn't always work, see [#79308]
6666//!
7070//! Since unchecked accesses through that trait do not advance the read pointer of `IntoIter`
7171//! this would interact unsoundly with the requirements about dropping the tail described above.
7272//! But since the normal `Drop` implementation of `IntoIter` would suffer from the same problem it
73- //! is only correct for `TrustedRandomAccessNoCoerce ` to be implemented when the items don't
73+ //! is only correct for `TrustedRandomAccess ` to be implemented when the items don't
7474//! have a destructor. Thus that implicit requirement also makes the specialization safe to use for
7575//! in-place collection.
7676//! Note that this safety concern is about the correctness of `impl Drop for IntoIter`,
134134//! }
135135//! vec.truncate(write_idx);
136136//! ```
137- use core:: iter:: { InPlaceIterable , SourceIter , TrustedRandomAccessNoCoerce } ;
137+ use core:: iter:: { InPlaceIterable , SourceIter , TrustedRandomAccess } ;
138138use core:: mem:: { self , ManuallyDrop } ;
139139use core:: ptr:: { self } ;
140140
@@ -195,7 +195,7 @@ where
195195 // itself once IntoIter goes out of scope.
196196 // If the drop panics then we also leak any elements collected into dst_buf.
197197 //
198- // Note: This access to the source wouldn't be allowed by the TrustedRandomIteratorNoCoerce
198+ // Note: This access to the source wouldn't be allowed by the TrustedRandomIterator
199199 // contract (used by SpecInPlaceCollect below). But see the "O(1) collect" section in the
200200 // module documenttation why this is ok anyway.
201201 src. forget_allocation_drop_remaining ( ) ;
@@ -230,7 +230,7 @@ trait SpecInPlaceCollect<T, I>: Iterator<Item = T> {
230230 /// collected. `end` is the last writable element of the allocation and used for bounds checks.
231231 ///
232232 /// This method is specialized and one of its implementations makes use of
233- /// `Iterator::__iterator_get_unchecked` calls with a `TrustedRandomAccessNoCoerce ` bound
233+ /// `Iterator::__iterator_get_unchecked` calls with a `TrustedRandomAccess ` bound
234234 /// on `I` which means the caller of this method must take the safety conditions
235235 /// of that trait into consideration.
236236 fn collect_in_place ( & mut self , dst : * mut T , end : * const T ) -> usize ;
@@ -256,7 +256,7 @@ where
256256
257257impl < T , I > SpecInPlaceCollect < T , I > for I
258258where
259- I : Iterator < Item = T > + TrustedRandomAccessNoCoerce ,
259+ I : Iterator < Item = T > + TrustedRandomAccess ,
260260{
261261 #[ inline]
262262 fn collect_in_place ( & mut self , dst_buf : * mut T , end : * const T ) -> usize {
0 commit comments