Skip to content

Commit

Permalink
Rename Iterator::get_unchecked -> Iterator::__iterator_get_unchecked
Browse files Browse the repository at this point in the history
Backport of rust-lang#77201, manually done because of file renaming.
  • Loading branch information
Mark-Simulacrum committed Sep 28, 2020
1 parent aac490a commit 656fa79
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
}

#[inline]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
{
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ where
self.it.count()
}

unsafe fn get_unchecked(&mut self, idx: usize) -> T
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
where
Self: TrustedRandomAccess,
{
Expand Down Expand Up @@ -350,7 +350,7 @@ where
self.it.map(T::clone).fold(init, f)
}

unsafe fn get_unchecked(&mut self, idx: usize) -> T
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
where
Self: TrustedRandomAccess,
{
Expand Down Expand Up @@ -865,7 +865,7 @@ where
self.iter.fold(init, map_fold(self.f, g))
}

unsafe fn get_unchecked(&mut self, idx: usize) -> B
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
where
Self: TrustedRandomAccess,
{
Expand Down Expand Up @@ -1304,7 +1304,7 @@ where
self.iter.fold(init, enumerate(self.count, fold))
}

unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
where
Self: TrustedRandomAccess,
{
Expand Down
20 changes: 12 additions & 8 deletions library/core/src/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
}

#[inline]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
{
Expand Down Expand Up @@ -197,12 +197,14 @@ where
let i = self.index;
self.index += 1;
// SAFETY: `i` is smaller than `self.len`, thus smaller than `self.a.len()` and `self.b.len()`
unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
unsafe {
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
}
} else if A::may_have_side_effect() && self.index < self.a.size() {
// match the base implementation's potential side effects
// SAFETY: we just checked that `self.index` < `self.a.len()`
unsafe {
self.a.get_unchecked(self.index);
self.a.__iterator_get_unchecked(self.index);
}
self.index += 1;
None
Expand All @@ -229,13 +231,13 @@ where
// ensures that `end` is smaller than or equal to `self.len`,
// so `i` is also smaller than `self.len`.
unsafe {
self.a.get_unchecked(i);
self.a.__iterator_get_unchecked(i);
}
}
if B::may_have_side_effect() {
// SAFETY: same as above.
unsafe {
self.b.get_unchecked(i);
self.b.__iterator_get_unchecked(i);
}
}
}
Expand Down Expand Up @@ -277,7 +279,9 @@ where
let i = self.len;
// SAFETY: `i` is smaller than the previous value of `self.len`,
// which is also smaller than or equal to `self.a.len()` and `self.b.len()`
unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
unsafe {
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
}
} else {
None
}
Expand All @@ -287,7 +291,7 @@ where
unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item {
// SAFETY: the caller must uphold the contract for
// `Iterator::get_unchecked`.
unsafe { (self.a.get_unchecked(idx), self.b.get_unchecked(idx)) }
unsafe { (self.a.__iterator_get_unchecked(idx), self.b.__iterator_get_unchecked(idx)) }
}
}

Expand Down Expand Up @@ -430,6 +434,6 @@ unsafe impl<I: Iterator + TrustedRandomAccess> SpecTrustedRandomAccess for I {
unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item {
// SAFETY: the caller must uphold the contract for
// `Iterator::get_unchecked`.
unsafe { self.get_unchecked(index) }
unsafe { self.__iterator_get_unchecked(index) }
}
}
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3251,7 +3251,7 @@ pub trait Iterator {
#[inline]
#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
unsafe fn get_unchecked(&mut self, _idx: usize) -> Self::Item
unsafe fn __iterator_get_unchecked(&mut self, _idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
{
Expand Down
24 changes: 12 additions & 12 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3922,7 +3922,7 @@ macro_rules! iterator {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
// SAFETY: the caller must guarantee that `i` is in bounds of
// the underlying slice, so `i` cannot overflow an `isize`, and
// the returned references is guaranteed to refer to an element
Expand Down Expand Up @@ -5022,7 +5022,7 @@ impl<'a, T> Iterator for Windows<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
// SAFETY: since the caller guarantees that `i` is in bounds,
// which means that `i` cannot overflow an `isize`, and the
// slice created by `from_raw_parts` is a subslice of `self.v`
Expand Down Expand Up @@ -5161,7 +5161,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let start = idx * self.chunk_size;
let end = match start.checked_add(self.chunk_size) {
None => self.v.len(),
Expand Down Expand Up @@ -5310,7 +5310,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let start = idx * self.chunk_size;
let end = match start.checked_add(self.chunk_size) {
None => self.v.len(),
Expand Down Expand Up @@ -5463,7 +5463,7 @@ impl<'a, T> Iterator for ChunksExact<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let start = idx * self.chunk_size;
// SAFETY: mostly identical to `Chunks::get_unchecked`.
unsafe { from_raw_parts(self.v.as_ptr().add(start), self.chunk_size) }
Expand Down Expand Up @@ -5597,7 +5597,7 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let start = idx * self.chunk_size;
// SAFETY: see comments for `ChunksMut::get_unchecked`.
unsafe { from_raw_parts_mut(self.v.as_mut_ptr().add(start), self.chunk_size) }
Expand Down Expand Up @@ -5723,10 +5723,10 @@ impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> {
self.iter.last()
}

unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T; N] {
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a [T; N] {
// SAFETY: The safety guarantees of `get_unchecked` are transferred to
// the caller.
unsafe { self.iter.get_unchecked(i) }
unsafe { self.iter.__iterator_get_unchecked(i) }
}
}

Expand Down Expand Up @@ -5853,7 +5853,7 @@ impl<'a, T> Iterator for RChunks<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let end = self.v.len() - idx * self.chunk_size;
let start = match end.checked_sub(self.chunk_size) {
None => 0,
Expand Down Expand Up @@ -5999,7 +5999,7 @@ impl<'a, T> Iterator for RChunksMut<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let end = self.v.len() - idx * self.chunk_size;
let start = match end.checked_sub(self.chunk_size) {
None => 0,
Expand Down Expand Up @@ -6145,7 +6145,7 @@ impl<'a, T> Iterator for RChunksExact<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let end = self.v.len() - idx * self.chunk_size;
let start = end - self.chunk_size;
// SAFETY:
Expand Down Expand Up @@ -6286,7 +6286,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
}

#[doc(hidden)]
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
let end = self.v.len() - idx * self.chunk_size;
let start = end - self.chunk_size;
// SAFETY: see comments for `RChunksMut::get_unchecked`.
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,10 @@ impl Iterator for Bytes<'_> {
}

#[inline]
unsafe fn get_unchecked(&mut self, idx: usize) -> u8 {
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> u8 {
// SAFETY: the caller must uphold the safety contract
// for `Iterator::get_unchecked`.
unsafe { self.0.get_unchecked(idx) }
unsafe { self.0.__iterator_get_unchecked(idx) }
}
}

Expand Down

0 comments on commit 656fa79

Please sign in to comment.