Skip to content

Commit 1b3bc16

Browse files
committed
Fix out of bounds access by checking length equality BEFORE accessing by index.
Fixes #5780
1 parent be88122 commit 1b3bc16

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/unnested_or_patterns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ fn extend_with_matching(
400400

401401
/// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`?
402402
fn eq_pre_post(ps1: &[P<Pat>], ps2: &[P<Pat>], idx: usize) -> bool {
403-
ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
404-
&& ps1.len() == ps2.len()
403+
ps1.len() == ps2.len()
404+
&& ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
405405
&& over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r))
406406
&& over(&ps1[idx + 1..], &ps2[idx + 1..], |l, r| eq_pat(l, r))
407407
}

0 commit comments

Comments
 (0)