Skip to content

Commit 01f49b0

Browse files
committed
Clarify WindowsMut (Lending)Iterator
fixes 133628
1 parent b5741a3 commit 01f49b0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/core/src/slice/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,14 @@ impl<T> [T] {
10991099
/// assert!(iter.next().is_none());
11001100
/// ```
11011101
///
1102-
/// There's no `windows_mut`, as that existing would let safe code violate the
1103-
/// "only one `&mut` at a time to the same thing" rule. However, you can sometimes
1104-
/// use [`Cell::as_slice_of_cells`](crate::cell::Cell::as_slice_of_cells) in
1105-
/// conjunction with `windows` to accomplish something similar:
1102+
/// Because the [Iterator] trait cannot represent the required lifetimes, there is no `windows_mut` analog to `windows`;
1103+
/// `[0,1,2].windows_mut(2).collect()` would violate [the rules of references]
1104+
/// (though a [LendingIterator] analog is possible).
1105+
/// You can sometimes use [`Cell::as_slice_of_cells`](crate::cell::Cell::as_slice_of_cells) in
1106+
/// conjunction with `windows` instead:
1107+
///
1108+
/// [the rules of references]: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#the-rules-of-references
1109+
/// [LendingIterator]: https://blog.rust-lang.org/2022/10/28/gats-stabilization.html
11061110
/// ```
11071111
/// use std::cell::Cell;
11081112
///

0 commit comments

Comments
 (0)