Skip to content

Commit

Permalink
Auto merge of rust-lang#84135 - rust-lang:GuillaumeGomez-patch-1, r=k…
Browse files Browse the repository at this point in the history
…ennytm

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.
  • Loading branch information
bors committed Apr 13, 2021
2 parents 5258a74 + b89c464 commit 5c13042
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 };
/// # let mut vec = vec![1, 2, 3, 4, 5, 6];
/// let mut i = 0;
/// while i != vec.len() {
/// while i < vec.len() {
/// if some_predicate(&mut vec[i]) {
/// let val = vec.remove(i);
/// // your code here
Expand Down

0 comments on commit 5c13042

Please sign in to comment.