Skip to content

Commit 5c13042

Browse files
committed
Auto merge of #84135 - rust-lang:GuillaumeGomez-patch-1, r=kennytm
Improve code example for length comparison Small fix/improvement: it's much safer to check that you're under the length of an array rather than chacking that you're equal to it. It's even more true in case you update the length of the array while iterating.
2 parents 5258a74 + b89c464 commit 5c13042

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/alloc/src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ impl<T, A: Allocator> Vec<T, A> {
25672567
/// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 };
25682568
/// # let mut vec = vec![1, 2, 3, 4, 5, 6];
25692569
/// let mut i = 0;
2570-
/// while i != vec.len() {
2570+
/// while i < vec.len() {
25712571
/// if some_predicate(&mut vec[i]) {
25722572
/// let val = vec.remove(i);
25732573
/// // your code here

0 commit comments

Comments
 (0)