92
92
#[ doc( hidden) ]
93
93
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> Self :: Item
94
94
where
95
- Self : TrustedRandomAccessNoCoerce ,
95
+ Self : TrustedRandomAccess ,
96
96
{
97
97
// SAFETY: the caller must uphold the contract for
98
98
// `Iterator::__iterator_get_unchecked`.
@@ -257,15 +257,6 @@ unsafe impl<A, B> TrustedRandomAccess for Zip<A, B>
257
257
where
258
258
A : TrustedRandomAccess ,
259
259
B : TrustedRandomAccess ,
260
- {
261
- }
262
-
263
- #[ doc( hidden) ]
264
- #[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
265
- unsafe impl < A , B > TrustedRandomAccessNoCoerce for Zip < A , B >
266
- where
267
- A : TrustedRandomAccessNoCoerce ,
268
- B : TrustedRandomAccessNoCoerce ,
269
260
{
270
261
const NEEDS_CLEANUP : bool = A :: NEEDS_CLEANUP || B :: NEEDS_CLEANUP ;
271
262
@@ -328,9 +319,7 @@ impl<A: Debug, B: Debug> ZipFmt<A, B> for Zip<A, B> {
328
319
}
329
320
}
330
321
331
- impl < A : Debug + TrustedRandomAccessNoCoerce , B : Debug + TrustedRandomAccessNoCoerce > ZipFmt < A , B >
332
- for Zip < A , B >
333
- {
322
+ impl < A : Debug + TrustedRandomAccess , B : Debug + TrustedRandomAccess > ZipFmt < A , B > for Zip < A , B > {
334
323
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
335
324
// It's *not safe* to call fmt on the contained iterators, since once
336
325
// we start iterating they're in strange, potentially unsafe, states.
@@ -344,7 +333,7 @@ impl<A: Debug + TrustedRandomAccessNoCoerce, B: Debug + TrustedRandomAccessNoCoe
344
333
///
345
334
/// The iterator's `size_hint` must be exact and cheap to call.
346
335
///
347
- /// `TrustedRandomAccessNoCoerce ::size` may not be overridden.
336
+ /// `TrustedRandomAccess ::size` may not be overridden.
348
337
///
349
338
/// All subtypes and all supertypes of `Self` must also implement `TrustedRandomAccess`.
350
339
/// In particular, this means that types with non-invariant parameters usually can not have
@@ -372,42 +361,21 @@ impl<A: Debug + TrustedRandomAccessNoCoerce, B: Debug + TrustedRandomAccessNoCoe
372
361
/// * `std::iter::DoubleEndedIterator::next_back`
373
362
/// * `std::iter::ExactSizeIterator::len`
374
363
/// * `std::iter::Iterator::__iterator_get_unchecked`
375
- /// * `std::iter::TrustedRandomAccessNoCoerce::size`
376
- /// 5. If `T` is a subtype of `Self`, then `self` is allowed to be coerced
377
- /// to `T`. If `self` is coerced to `T` after `self.__iterator_get_unchecked(idx)` has already
378
- /// been called, then no methods except for the ones listed under 4. are allowed to be called
379
- /// on the resulting value of type `T`, either. Multiple such coercion steps are allowed.
380
- /// Regarding 2. and 3., the number of times `__iterator_get_unchecked(idx)` or `next_back()` is
381
- /// called on `self` and the resulting value of type `T` (and on further coercion results with
382
- /// sub-subtypes) are added together and their sums must not exceed the specified bounds.
364
+ /// * `std::iter::TrustedRandomAccess::size`
383
365
///
384
366
/// Further, given that these conditions are met, it must guarantee that:
385
367
///
386
368
/// * It does not change the value returned from `size_hint`
387
369
/// * It must be safe to call the methods listed above on `self` after calling
388
370
/// `self.__iterator_get_unchecked(idx)`, assuming that the required traits are implemented.
389
371
/// * It must also be safe to drop `self` after calling `self.__iterator_get_unchecked(idx)`.
390
- /// * If `T` is a subtype of `Self`, then it must be safe to coerce `self` to `T`.
391
372
//
392
373
// FIXME: Clarify interaction with SourceIter/InPlaceIterable. Calling `SourceIter::as_inner`
393
374
// after `__iterator_get_unchecked` is supposed to be allowed.
394
375
#[ doc( hidden) ]
395
376
#[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
396
377
#[ rustc_specialization_trait]
397
- pub unsafe trait TrustedRandomAccess : TrustedRandomAccessNoCoerce { }
398
-
399
- /// Like [`TrustedRandomAccess`] but without any of the requirements / guarantees around
400
- /// coercions to subtypes after `__iterator_get_unchecked` (they aren’t allowed here!), and
401
- /// without the requirement that subtypes / supertypes implement `TrustedRandomAccessNoCoerce`.
402
- ///
403
- /// This trait was created in PR #85874 to fix soundness issue #85873 without performance regressions.
404
- /// It is subject to change as we might want to build a more generally useful (for performance
405
- /// optimizations) and more sophisticated trait or trait hierarchy that replaces or extends
406
- /// [`TrustedRandomAccess`] and `TrustedRandomAccessNoCoerce`.
407
- #[ doc( hidden) ]
408
- #[ unstable( feature = "trusted_random_access" , issue = "none" ) ]
409
- #[ rustc_specialization_trait]
410
- pub unsafe trait TrustedRandomAccessNoCoerce : Sized {
378
+ pub unsafe trait TrustedRandomAccess : Sized {
411
379
// Convenience method.
412
380
fn size ( & self ) -> usize
413
381
where
@@ -450,7 +418,7 @@ unsafe impl<I: Iterator> SpecTrustedRandomAccess for I {
450
418
}
451
419
}
452
420
453
- unsafe impl < I : Iterator + TrustedRandomAccessNoCoerce > SpecTrustedRandomAccess for I {
421
+ unsafe impl < I : Iterator + TrustedRandomAccess > SpecTrustedRandomAccess for I {
454
422
#[ inline]
455
423
unsafe fn try_get_unchecked ( & mut self , index : usize ) -> Self :: Item {
456
424
// SAFETY: the caller must uphold the contract for
0 commit comments