Skip to content

Commit c9be90a

Browse files
committed
Auto merge of rust-lang#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 5490a07 + 5a0e354 commit c9be90a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)