Skip to content

Commit

Permalink
Rollup merge of rust-lang#110997 - scottmcm:slice-iter-comments, r=th…
Browse files Browse the repository at this point in the history
…e8472

Improve internal field comments on `slice::Iter(Mut)`

I wrote these in a previous PR that I ended up withdrawing, so might as well submit them separately.

`@bors` rollup=always
  • Loading branch information
matthiaskrgr authored Apr 29, 2023
2 parents a656a20 + 57aac3f commit f720813
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ impl<'a, T> IntoIterator for &'a mut [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Iter<'a, T: 'a> {
/// The pointer to the next element to return, or the past-the-end location
/// if the iterator is empty.
///
/// This address will be used for all ZST elements, never changed.
ptr: NonNull<T>,
end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
// ptr == end is a quick test for the Iterator being empty, that works
// for both ZST and non-ZST.
/// For non-ZSTs, the non-null pointer to the past-the-end element.
///
/// For ZSTs, this is `ptr.wrapping_byte_add(len)`.
///
/// For all types, `ptr == end` tests whether the iterator is empty.
end: *const T,
_marker: PhantomData<&'a T>,
}

Expand Down Expand Up @@ -179,10 +186,17 @@ impl<T> AsRef<[T]> for Iter<'_, T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct IterMut<'a, T: 'a> {
/// The pointer to the next element to return, or the past-the-end location
/// if the iterator is empty.
///
/// This address will be used for all ZST elements, never changed.
ptr: NonNull<T>,
end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
// ptr == end is a quick test for the Iterator being empty, that works
// for both ZST and non-ZST.
/// For non-ZSTs, the non-null pointer to the past-the-end element.
///
/// For ZSTs, this is `ptr.wrapping_byte_add(len)`.
///
/// For all types, `ptr == end` tests whether the iterator is empty.
end: *mut T,
_marker: PhantomData<&'a mut T>,
}

Expand Down

0 comments on commit f720813

Please sign in to comment.