Skip to content

Commit ce850bf

Browse files
committed
array_chunks: slightly improve docs
1 parent 4146079 commit ce850bf

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

library/core/src/array/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ where
907907
/// All write accesses to this structure are unsafe and must maintain a correct
908908
/// count of `initialized` elements.
909909
///
910-
/// To minimize indirection fields are still pub but callers should at least use
910+
/// To minimize indirection, fields are still pub but callers should at least use
911911
/// `push_unchecked` to signal that something unsafe is going on.
912912
struct Guard<'a, T> {
913913
/// The array to be initialized.
@@ -925,7 +925,7 @@ impl<T> Guard<'_, T> {
925925
#[inline]
926926
pub(crate) unsafe fn push_unchecked(&mut self, item: T) {
927927
// SAFETY: If `initialized` was correct before and the caller does not
928-
// invoke this method more than N times then writes will be in-bounds
928+
// invoke this method more than N times, then writes will be in-bounds
929929
// and slots will not be initialized more than once.
930930
unsafe {
931931
self.array_mut.get_unchecked_mut(self.initialized).write(item);
@@ -954,7 +954,7 @@ impl<T> Drop for Guard<'_, T> {
954954
/// `next` at most `N` times, the iterator can still be used afterwards to
955955
/// retrieve the remaining items.
956956
///
957-
/// If `iter.next()` panicks, all items already yielded by the iterator are
957+
/// If `iter.next()` panics, all items already yielded by the iterator are
958958
/// dropped.
959959
///
960960
/// Used for [`Iterator::next_chunk`].
@@ -986,6 +986,7 @@ fn iter_next_chunk_erased<T>(
986986
buffer: &mut [MaybeUninit<T>],
987987
iter: &mut impl Iterator<Item = T>,
988988
) -> Result<(), usize> {
989+
// if `Iterator::next` panics, this guard will drop already initialized items
989990
let mut guard = Guard { array_mut: buffer, initialized: 0 };
990991
while guard.initialized < guard.array_mut.len() {
991992
let Some(item) = iter.next() else {

library/core/src/iter/adapters/array_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
match self.iter.next_chunk() {
9090
Ok(chunk) => acc = f(acc, chunk)?,
9191
Err(remainder) => {
92-
// Make sure to not override `self.remainder` with an empty array
92+
// Make sure to not overwrite `self.remainder` with an empty array
9393
// when `next` is called after `ArrayChunks` exhaustion.
9494
self.remainder.get_or_insert(remainder);
9595

0 commit comments

Comments
 (0)