check on a per-body level instead of blocks independently

This commit is contained in:
y21 2023-11-23 08:48:36 +01:00
parent 72c0d80f46
commit 553857bb2b
3 changed files with 45 additions and 4 deletions

View file

@ -46,4 +46,26 @@ fn index_struct_different_fields(f: &Foo<'_>) {
let _ = f.v[0] + f.v2[1];
}
fn shadowing() {
let x: &[i32] = &[1];
assert!(x.len() > 1);
let x: &[i32] = &[1];
let _ = x[0] + x[1];
//~^ ERROR: indexing into a slice multiple times without an `assert`
}
pub fn issue11856(values: &[i32]) -> usize {
let mut ascending = Vec::new();
for w in values.windows(2) {
assert!(w.len() > 1);
if w[0] < w[1] {
ascending.push((w[0], w[1]));
} else {
ascending.push((w[1], w[0]));
}
}
ascending.len()
}
fn main() {}

View file

@ -160,5 +160,24 @@ LL | let _ = f.v[0] + f.v[1];
| ^^^^^^
= note: asserting the length before indexing will elide bounds checks
error: aborting due to 7 previous errors
error: indexing into a slice multiple times without an `assert`
--> $DIR/missing_asserts_for_indexing_unfixable.rs:54:13
|
LL | let _ = x[0] + x[1];
| ^^^^^^^^^^^
|
= help: consider asserting the length before indexing: `assert!(x.len() > 1);`
note: slice indexed here
--> $DIR/missing_asserts_for_indexing_unfixable.rs:54:13
|
LL | let _ = x[0] + x[1];
| ^^^^
note: slice indexed here
--> $DIR/missing_asserts_for_indexing_unfixable.rs:54:20
|
LL | let _ = x[0] + x[1];
| ^^^^
= note: asserting the length before indexing will elide bounds checks
error: aborting due to 8 previous errors