@@ -354,6 +354,15 @@ unsafe impl<A, B> TrustedRandomAccess for Zip<A, B>
354354where
355355 A : TrustedRandomAccess ,
356356 B : TrustedRandomAccess ,
357+ {
358+ }
359+
360+ #[ doc( hidden) ]
361+ #[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
362+ unsafe impl < A , B > TrustedRandomAccessNoCoerce for Zip < A , B >
363+ where
364+ A : TrustedRandomAccessNoCoerce ,
365+ B : TrustedRandomAccessNoCoerce ,
357366{
358367 const MAY_HAVE_SIDE_EFFECT : bool = A :: MAY_HAVE_SIDE_EFFECT || B :: MAY_HAVE_SIDE_EFFECT ;
359368}
@@ -431,7 +440,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
431440///
432441/// The iterator's `size_hint` must be exact and cheap to call.
433442///
434- /// `size` may not be overridden.
443+ /// `TrustedRandomAccessNoCoerce:: size` may not be overridden.
435444///
436445/// All subtypes and all supertypes of `Self` must also implement `TrustedRandomAccess`.
437446/// In particular, this means that types with non-invariant parameters usually can not have
@@ -455,7 +464,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
455464/// * `std::iter::Iterator::size_hint`
456465/// * `std::iter::DoubleEndedIterator::next_back`
457466/// * `std::iter::Iterator::__iterator_get_unchecked`
458- /// * `std::iter::TrustedRandomAccess ::size`
467+ /// * `std::iter::TrustedRandomAccessNoCoerce ::size`
459468/// 5. If `T` is a subtype of `Self`, then `self` is allowed to be coerced
460469/// to `T`. If `self` is coerced to `T` after `self.__iterator_get_unchecked(idx)` has already
461470/// been called, then no methods except for the ones listed under 4. are allowed to be called
@@ -474,7 +483,15 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
474483#[ doc( hidden) ]
475484#[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
476485#[ rustc_specialization_trait]
477- pub unsafe trait TrustedRandomAccess : Sized {
486+ pub unsafe trait TrustedRandomAccess : TrustedRandomAccessNoCoerce { }
487+
488+ /// Like [`TrustedRandomAccess`] but without any of the requirements / guarantees around
489+ /// coercions to subtypes after `__iterator_get_unchecked` (they aren’t allowed here!), and
490+ /// without the requirement that subtypes / supertypes implement [`TrustedRandomAccessNoCoerce`].
491+ #[ doc( hidden) ]
492+ #[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
493+ #[ rustc_specialization_trait]
494+ pub unsafe trait TrustedRandomAccessNoCoerce : Sized {
478495 // Convenience method.
479496 fn size ( & self ) -> usize
480497 where
0 commit comments