diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-07-22 13:39:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-22 13:39:24 +0200 |
| commit | aece3df81e9ebd8bab3701e12bdb67b68c03564b (patch) | |
| tree | 88e58ffd03a8620e9c1b11b4b7c817b119c4ddce | |
| parent | 90d6d3327d7d40f1f0c8e524c5e40f658070c90f (diff) | |
| parent | 1b66a799c7ef707d2cd4b325b654e69bf536c30f (diff) | |
| download | rust-aece3df81e9ebd8bab3701e12bdb67b68c03564b.tar.gz rust-aece3df81e9ebd8bab3701e12bdb67b68c03564b.zip | |
Rollup merge of #87343 - steffahn:fix_unsound_zip_optimization_only_regression_fix, r=cuviper
Regression fix to avoid further beta backports: Remove unsound TrustedRandomAccess implementations Removes the implementations that depend on the user-definable trait `Copy`. Only fix regressions to ensure merge in 1.55: Does not modify `vec::IntoIter`. <hr> This PR applies the beta-`1.53` backport #86222 (merged as part of #86225), a reduced version of #85874 that only fixes regressions, to `master` in order to avoid the need for further backports from `1.55` onwards. Beta-`1.54` backport already happened with #87136. In case that #85874 gets merged quickly (within a week), this PR would be unnecessary. r? `@cuviper`
| -rw-r--r-- | library/alloc/src/collections/vec_deque/into_iter.rs | 30 | ||||
| -rw-r--r-- | library/core/src/array/iter.rs | 26 |
2 files changed, 2 insertions, 54 deletions
diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 46a769a722a..612f7e6eb4d 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,5 +1,5 @@ use core::fmt; -use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess}; +use core::iter::{FusedIterator, TrustedLen}; use super::VecDeque; @@ -36,23 +36,6 @@ impl<T> Iterator for IntoIter<T> { let len = self.inner.len(); (len, Some(len)) } - - #[inline] - #[doc(hidden)] - unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item - where - Self: TrustedRandomAccess, - { - // Safety: The TrustedRandomAccess contract requires that callers only pass an index - // that is in bounds. - // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even - // multiple repeated reads of the same index would be safe and the - // values are !Drop, thus won't suffer from double drops. - unsafe { - let idx = self.inner.wrap_add(self.inner.tail, idx); - self.inner.buffer_read(idx) - } - } } #[stable(feature = "rust1", since = "1.0.0")] @@ -75,14 +58,3 @@ impl<T> FusedIterator for IntoIter<T> {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl<T> TrustedLen for IntoIter<T> {} - -#[doc(hidden)] -#[unstable(feature = "trusted_random_access", issue = "none")] -// T: Copy as approximation for !Drop since get_unchecked does not update the pointers -// and thus we can't implement drop-handling -unsafe impl<T> TrustedRandomAccess for IntoIter<T> -where - T: Copy, -{ - const MAY_HAVE_SIDE_EFFECT: bool = false; -} diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 931ea77eca4..61ab1b1faff 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -2,7 +2,7 @@ use crate::{ fmt, - iter::{self, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess}, + iter::{self, ExactSizeIterator, FusedIterator, TrustedLen}, mem::{self, MaybeUninit}, ops::Range, ptr, @@ -130,19 +130,6 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> { fn last(mut self) -> Option<Self::Item> { self.next_back() } - - #[inline] - #[doc(hidden)] - unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item - where - Self: TrustedRandomAccess, - { - // SAFETY: Callers are only allowed to pass an index that is in bounds - // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even - // multiple repeated reads of the same index would be safe and the - // values are !Drop, thus won't suffer from double drops. - unsafe { self.data.get_unchecked(self.alive.start + idx).assume_init_read() } - } } #[stable(feature = "array_value_iter_impls", since = "1.40.0")] @@ -197,17 +184,6 @@ impl<T, const N: usize> FusedIterator for IntoIter<T, N> {} #[stable(feature = "array_value_iter_impls", since = "1.40.0")] unsafe impl<T, const N: usize> TrustedLen for IntoIter<T, N> {} -#[doc(hidden)] -#[unstable(feature = "trusted_random_access", issue = "none")] -// T: Copy as approximation for !Drop since get_unchecked does not update the pointers -// and thus we can't implement drop-handling -unsafe impl<T, const N: usize> TrustedRandomAccess for IntoIter<T, N> -where - T: Copy, -{ - const MAY_HAVE_SIDE_EFFECT: bool = false; -} - #[stable(feature = "array_value_iter_impls", since = "1.40.0")] impl<T: Clone, const N: usize> Clone for IntoIter<T, N> { fn clone(&self) -> Self { |
