Skip to content

Commit 3a5d335

Browse files
committedJul 20, 2021
Auto merge of rust-lang#87136 - cuviper:redo-86222, r=Mark-Simulacrum
[beta] Remove unsound TrustedRandomAccess implementations This re-applies rust-lang#86222 for 1.54, as the larger fixes in rust-lang#85874 are still in progress.

File tree

2 files changed

+2
-52
lines changed

2 files changed

+2
-52
lines changed
 

‎library/alloc/src/collections/vec_deque/into_iter.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::fmt;
2-
use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess};
2+
use core::iter::{FusedIterator, TrustedLen};
33

44
use super::VecDeque;
55

@@ -36,22 +36,6 @@ impl<T> Iterator for IntoIter<T> {
3636
let len = self.inner.len();
3737
(len, Some(len))
3838
}
39-
40-
#[inline]
41-
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
42-
where
43-
Self: TrustedRandomAccess,
44-
{
45-
// Safety: The TrustedRandomAccess contract requires that callers only pass an index
46-
// that is in bounds.
47-
// Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even
48-
// multiple repeated reads of the same index would be safe and the
49-
// values are !Drop, thus won't suffer from double drops.
50-
unsafe {
51-
let idx = self.inner.wrap_add(self.inner.tail, idx);
52-
self.inner.buffer_read(idx)
53-
}
54-
}
5539
}
5640

5741
#[stable(feature = "rust1", since = "1.0.0")]
@@ -74,14 +58,3 @@ impl<T> FusedIterator for IntoIter<T> {}
7458

7559
#[unstable(feature = "trusted_len", issue = "37572")]
7660
unsafe impl<T> TrustedLen for IntoIter<T> {}
77-
78-
#[doc(hidden)]
79-
#[unstable(feature = "trusted_random_access", issue = "none")]
80-
// T: Copy as approximation for !Drop since get_unchecked does not update the pointers
81-
// and thus we can't implement drop-handling
82-
unsafe impl<T> TrustedRandomAccess for IntoIter<T>
83-
where
84-
T: Copy,
85-
{
86-
const MAY_HAVE_SIDE_EFFECT: bool = false;
87-
}

‎library/core/src/array/iter.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
fmt,
5-
iter::{self, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess},
5+
iter::{self, ExactSizeIterator, FusedIterator, TrustedLen},
66
mem::{self, MaybeUninit},
77
ops::Range,
88
ptr,
@@ -130,18 +130,6 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
130130
fn last(mut self) -> Option<Self::Item> {
131131
self.next_back()
132132
}
133-
134-
#[inline]
135-
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
136-
where
137-
Self: TrustedRandomAccess,
138-
{
139-
// SAFETY: Callers are only allowed to pass an index that is in bounds
140-
// Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even
141-
// multiple repeated reads of the same index would be safe and the
142-
// values are !Drop, thus won't suffer from double drops.
143-
unsafe { self.data.get_unchecked(self.alive.start + idx).assume_init_read() }
144-
}
145133
}
146134

147135
#[stable(feature = "array_value_iter_impls", since = "1.40.0")]
@@ -196,17 +184,6 @@ impl<T, const N: usize> FusedIterator for IntoIter<T, N> {}
196184
#[stable(feature = "array_value_iter_impls", since = "1.40.0")]
197185
unsafe impl<T, const N: usize> TrustedLen for IntoIter<T, N> {}
198186

199-
#[doc(hidden)]
200-
#[unstable(feature = "trusted_random_access", issue = "none")]
201-
// T: Copy as approximation for !Drop since get_unchecked does not update the pointers
202-
// and thus we can't implement drop-handling
203-
unsafe impl<T, const N: usize> TrustedRandomAccess for IntoIter<T, N>
204-
where
205-
T: Copy,
206-
{
207-
const MAY_HAVE_SIDE_EFFECT: bool = false;
208-
}
209-
210187
#[stable(feature = "array_value_iter_impls", since = "1.40.0")]
211188
impl<T: Clone, const N: usize> Clone for IntoIter<T, N> {
212189
fn clone(&self) -> Self {

0 commit comments

Comments
 (0)
Please sign in to comment.