Skip to content

Commit 97a11ff

Browse files
authored
Rollup merge of #148250 - hkBst:array-chunks-docs, r=joboet
array_chunks: slightly improve docs
2 parents b8338e9 + ce850bf commit 97a11ff

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
@@ -924,7 +924,7 @@ const fn try_from_fn_erased<R: [const] Try<Output: [const] Destruct>>(
924924
/// All write accesses to this structure are unsafe and must maintain a correct
925925
/// count of `initialized` elements.
926926
///
927-
/// To minimize indirection fields are still pub but callers should at least use
927+
/// To minimize indirection, fields are still pub but callers should at least use
928928
/// `push_unchecked` to signal that something unsafe is going on.
929929
struct Guard<'a, T> {
930930
/// The array to be initialized.
@@ -943,7 +943,7 @@ impl<T> Guard<'_, T> {
943943
#[rustc_const_unstable(feature = "array_try_from_fn", issue = "89379")]
944944
pub(crate) const unsafe fn push_unchecked(&mut self, item: T) {
945945
// SAFETY: If `initialized` was correct before and the caller does not
946-
// invoke this method more than N times then writes will be in-bounds
946+
// invoke this method more than N times, then writes will be in-bounds
947947
// and slots will not be initialized more than once.
948948
unsafe {
949949
self.array_mut.get_unchecked_mut(self.initialized).write(item);
@@ -972,7 +972,7 @@ impl<T: [const] Destruct> const Drop for Guard<'_, T> {
972972
/// `next` at most `N` times, the iterator can still be used afterwards to
973973
/// retrieve the remaining items.
974974
///
975-
/// If `iter.next()` panicks, all items already yielded by the iterator are
975+
/// If `iter.next()` panics, all items already yielded by the iterator are
976976
/// dropped.
977977
///
978978
/// Used for [`Iterator::next_chunk`].
@@ -1004,6 +1004,7 @@ fn iter_next_chunk_erased<T>(
10041004
buffer: &mut [MaybeUninit<T>],
10051005
iter: &mut impl Iterator<Item = T>,
10061006
) -> Result<(), usize> {
1007+
// if `Iterator::next` panics, this guard will drop already initialized items
10071008
let mut guard = Guard { array_mut: buffer, initialized: 0 };
10081009
while guard.initialized < guard.array_mut.len() {
10091010
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)