@@ -354,6 +354,15 @@ unsafe impl<A, B> TrustedRandomAccess for Zip<A, B>
354
354
where
355
355
A : TrustedRandomAccess ,
356
356
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 ,
357
366
{
358
367
const MAY_HAVE_SIDE_EFFECT : bool = A :: MAY_HAVE_SIDE_EFFECT || B :: MAY_HAVE_SIDE_EFFECT ;
359
368
}
@@ -431,7 +440,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
431
440
///
432
441
/// The iterator's `size_hint` must be exact and cheap to call.
433
442
///
434
- /// `size` may not be overridden.
443
+ /// `TrustedRandomAccessNoCoerce:: size` may not be overridden.
435
444
///
436
445
/// All subtypes and all supertypes of `Self` must also implement `TrustedRandomAccess`.
437
446
/// 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
455
464
/// * `std::iter::Iterator::size_hint`
456
465
/// * `std::iter::DoubleEndedIterator::next_back`
457
466
/// * `std::iter::Iterator::__iterator_get_unchecked`
458
- /// * `std::iter::TrustedRandomAccess ::size`
467
+ /// * `std::iter::TrustedRandomAccessNoCoerce ::size`
459
468
/// 5. If `T` is a subtype of `Self`, then `self` is allowed to be coerced
460
469
/// to `T`. If `self` is coerced to `T` after `self.__iterator_get_unchecked(idx)` has already
461
470
/// 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
474
483
#[ doc( hidden) ]
475
484
#[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
476
485
#[ 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 {
478
495
// Convenience method.
479
496
fn size ( & self ) -> usize
480
497
where
0 commit comments