diff options
author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-29 12:50:53 -0700 |
---|---|---|
committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-29 12:50:53 -0700 |
commit | 57aac3f671d32b2e2541c8907664f10af8c9db39 (patch) | |
tree | 3c0858e1d72d1784b5254833e2f70dff1b15fbc4 /library | |
parent | 43a78029b4f4d92978b8fde0a677ea300b113c41 (diff) | |
download | rust-57aac3f671d32b2e2541c8907664f10af8c9db39.tar.gz |
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.
Diffstat (limited to 'library')
-rw-r--r-- | library/core/src/slice/iter.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index b2dd92a2379..8629aab0070 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -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>, } @@ -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>, } |