diff --git a/clippy_lints/src/missing_asserts_for_indexing.rs b/clippy_lints/src/missing_asserts_for_indexing.rs index 03587a90707c..08fec2b8ec82 100644 --- a/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/clippy_lints/src/missing_asserts_for_indexing.rs @@ -1,14 +1,11 @@ use std::mem; use std::ops::ControlFlow; -use clippy_utils::eq_expr_value; +use clippy_utils::comparisons::{normalize_comparison, Rel}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; -use clippy_utils::{ - comparisons::{normalize_comparison, Rel}, - diagnostics::span_lint_and_then, - hash_expr, higher, - visitors::for_each_expr, -}; +use clippy_utils::visitors::for_each_expr; +use clippy_utils::{eq_expr_value, hash_expr, higher}; use rustc_ast::{LitKind, RangeLimits}; use rustc_data_structures::unhash::UnhashMap; use rustc_errors::{Applicability, Diagnostic}; @@ -220,13 +217,13 @@ fn upper_index_expr(expr: &Expr<'_>) -> Option { /// Checks if the expression is an index into a slice and adds it to `indexes` fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap>>) { - if let ExprKind::Index(slice, index_lit) = expr.kind + if let ExprKind::Index(slice, index_lit, _) = expr.kind && cx.typeck_results().expr_ty_adjusted(slice).peel_refs().is_slice() && let Some(index) = upper_index_expr(index_lit) { let hash = hash_expr(cx, slice); - let indexes = map.entry(hash).or_insert_with(Vec::new); + let indexes = map.entry(hash).or_default(); let entry = indexes.iter_mut().find(|entry| eq_expr_value(cx, entry.slice(), slice)); if let Some(entry) = entry { @@ -261,7 +258,7 @@ fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut Unh fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap>>) { if let Some((comparison, asserted_len, slice)) = assert_len_expr(cx, expr) { let hash = hash_expr(cx, slice); - let indexes = map.entry(hash).or_insert_with(Vec::new); + let indexes = map.entry(hash).or_default(); let entry = indexes.iter_mut().find(|entry| eq_expr_value(cx, entry.slice(), slice)); @@ -301,9 +298,10 @@ fn report_indexes(cx: &LateContext<'_>, map: &UnhashMap> let Some(full_span) = entry .index_spans() .and_then(|spans| spans.first().zip(spans.last())) - .map(|(low, &high)| low.to(high)) else { - continue; - }; + .map(|(low, &high)| low.to(high)) + else { + continue; + }; match entry { IndexEntry::AssertWithIndex { diff --git a/tests/ui/missing_asserts_for_indexing.fixed b/tests/ui/missing_asserts_for_indexing.fixed index 0dee4d76db5c..a96827259f53 100644 --- a/tests/ui/missing_asserts_for_indexing.fixed +++ b/tests/ui/missing_asserts_for_indexing.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::missing_asserts_for_indexing)] @@ -29,26 +27,26 @@ fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() > 4); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() > 4); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 4); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() > 4); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } // ok, don't lint for single array access @@ -65,8 +63,8 @@ fn subslice_ok(v: &[u8]) { fn subslice_bad(v: &[u8]) { assert!(v.len() > 3); - //~^ ERROR incorrect length let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v[1..4]; } @@ -79,8 +77,8 @@ fn subslice_inclusive_ok(v: &[u8]) { fn subslice_inclusive_bad(v: &[u8]) { assert!(v.len() > 4); - //~^ ERROR incorrect length let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v[1..=4]; } @@ -93,17 +91,17 @@ fn index_different_slices_ok(v1: &[u8], v2: &[u8]) { fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); - //~^ ERROR incorrect length assert!(v2.len() > 15); - //~^ ERROR incorrect length let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v2[5] + v2[15]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); - //~^ ERROR incorrect length assert!(v2.len() > 15); let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v2[5] + v2[15]; } diff --git a/tests/ui/missing_asserts_for_indexing.rs b/tests/ui/missing_asserts_for_indexing.rs index cddf82434a62..0b4b883acf8a 100644 --- a/tests/ui/missing_asserts_for_indexing.rs +++ b/tests/ui/missing_asserts_for_indexing.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::missing_asserts_for_indexing)] @@ -29,26 +27,26 @@ fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() < 5); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() <= 5); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 3); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() >= 4); - //~^ ERROR incorrect length v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } // ok, don't lint for single array access @@ -65,8 +63,8 @@ fn subslice_ok(v: &[u8]) { fn subslice_bad(v: &[u8]) { assert!(v.len() >= 3); - //~^ ERROR incorrect length let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v[1..4]; } @@ -79,8 +77,8 @@ fn subslice_inclusive_ok(v: &[u8]) { fn subslice_inclusive_bad(v: &[u8]) { assert!(v.len() >= 4); - //~^ ERROR incorrect length let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v[1..=4]; } @@ -93,17 +91,17 @@ fn index_different_slices_ok(v1: &[u8], v2: &[u8]) { fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() >= 12); - //~^ ERROR incorrect length assert!(v2.len() >= 15); - //~^ ERROR incorrect length let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v2[5] + v2[15]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() >= 12); - //~^ ERROR incorrect length assert!(v2.len() > 15); let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the let _ = v2[5] + v2[15]; } diff --git a/tests/ui/missing_asserts_for_indexing.stderr b/tests/ui/missing_asserts_for_indexing.stderr index b3c0ec8cf74d..75eb4a35cd46 100644 --- a/tests/ui/missing_asserts_for_indexing.stderr +++ b/tests/ui/missing_asserts_for_indexing.stderr @@ -1,34 +1,33 @@ error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:33:5 + --> $DIR/missing_asserts_for_indexing.rs:30:5 | LL | assert!(v.len() < 5); | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` -LL | //~^ ERROR incorrect length LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:33:5 + --> $DIR/missing_asserts_for_indexing.rs:30:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:33:12 + --> $DIR/missing_asserts_for_indexing.rs:30:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:33:19 + --> $DIR/missing_asserts_for_indexing.rs:30:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:33:26 + --> $DIR/missing_asserts_for_indexing.rs:30:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:33:33 + --> $DIR/missing_asserts_for_indexing.rs:30:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ @@ -36,182 +35,179 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings` error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:39:5 + --> $DIR/missing_asserts_for_indexing.rs:36:5 | LL | assert!(v.len() <= 5); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` -LL | //~^ ERROR incorrect length LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:39:5 + --> $DIR/missing_asserts_for_indexing.rs:36:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:39:12 + --> $DIR/missing_asserts_for_indexing.rs:36:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:39:19 + --> $DIR/missing_asserts_for_indexing.rs:36:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:39:26 + --> $DIR/missing_asserts_for_indexing.rs:36:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:39:33 + --> $DIR/missing_asserts_for_indexing.rs:36:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:45:5 + --> $DIR/missing_asserts_for_indexing.rs:42:5 | LL | assert!(v.len() > 3); | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` -LL | //~^ ERROR incorrect length LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:45:5 + --> $DIR/missing_asserts_for_indexing.rs:42:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:45:12 + --> $DIR/missing_asserts_for_indexing.rs:42:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:45:19 + --> $DIR/missing_asserts_for_indexing.rs:42:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:45:26 + --> $DIR/missing_asserts_for_indexing.rs:42:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:45:33 + --> $DIR/missing_asserts_for_indexing.rs:42:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:51:5 + --> $DIR/missing_asserts_for_indexing.rs:48:5 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` -LL | //~^ ERROR incorrect length LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:51:5 + --> $DIR/missing_asserts_for_indexing.rs:48:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:51:12 + --> $DIR/missing_asserts_for_indexing.rs:48:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:51:19 + --> $DIR/missing_asserts_for_indexing.rs:48:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:51:26 + --> $DIR/missing_asserts_for_indexing.rs:48:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:51:33 + --> $DIR/missing_asserts_for_indexing.rs:48:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:69:13 + --> $DIR/missing_asserts_for_indexing.rs:66:13 | LL | assert!(v.len() >= 3); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)` -LL | //~^ ERROR incorrect length LL | let _ = v[0]; | _____________^ +LL | | LL | | let _ = v[1..4]; | |___________________^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:69:13 + --> $DIR/missing_asserts_for_indexing.rs:66:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:70:13 + --> $DIR/missing_asserts_for_indexing.rs:68:13 | LL | let _ = v[1..4]; | ^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:83:13 + --> $DIR/missing_asserts_for_indexing.rs:80:13 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` -LL | //~^ ERROR incorrect length LL | let _ = v[0]; | _____________^ +LL | | LL | | let _ = v[1..=4]; | |____________________^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:83:13 + --> $DIR/missing_asserts_for_indexing.rs:80:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:84:13 + --> $DIR/missing_asserts_for_indexing.rs:82:13 | LL | let _ = v[1..=4]; | ^^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:99:13 + --> $DIR/missing_asserts_for_indexing.rs:95:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` -... +LL | assert!(v2.len() >= 15); LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:99:13 + --> $DIR/missing_asserts_for_indexing.rs:95:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:99:21 + --> $DIR/missing_asserts_for_indexing.rs:95:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:100:13 + --> $DIR/missing_asserts_for_indexing.rs:97:13 | LL | assert!(v2.len() >= 15); | ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)` @@ -220,33 +216,33 @@ LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:100:13 + --> $DIR/missing_asserts_for_indexing.rs:97:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:100:21 + --> $DIR/missing_asserts_for_indexing.rs:97:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> $DIR/missing_asserts_for_indexing.rs:106:13 + --> $DIR/missing_asserts_for_indexing.rs:103:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` -... +LL | assert!(v2.len() > 15); LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:106:13 + --> $DIR/missing_asserts_for_indexing.rs:103:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing.rs:106:21 + --> $DIR/missing_asserts_for_indexing.rs:103:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.rs b/tests/ui/missing_asserts_for_indexing_unfixable.rs index d157771bf7f6..4346ed892f27 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.rs +++ b/tests/ui/missing_asserts_for_indexing_unfixable.rs @@ -2,19 +2,19 @@ #![warn(clippy::missing_asserts_for_indexing)] fn sum(v: &[u8]) -> u8 { - //~^ ERROR missing assertions on `v.len()` v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times without an `assert` } fn subslice(v: &[u8]) { - //~^ ERROR missing assertion on `v.len()` let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times without an `assert` let _ = v[1..4]; } fn variables(v: &[u8]) -> u8 { - //~^ ERROR missing assertions on `v.len()` let a = v[0]; + //~^ ERROR: indexing into a slice multiple times without an `assert` let b = v[1]; let c = v[2]; a + b + c @@ -33,11 +33,17 @@ fn index_different_slices2(v1: &[u8], v2: &[u8]) { struct Foo<'a> { v: &'a [u8], + v2: &'a [u8], } fn index_struct_field(f: &Foo<'_>) { - //~^ ERROR missing assertion on `f.v.len()` let _ = f.v[0] + f.v[1]; + //~^ ERROR: indexing into a slice multiple times without an `assert` +} + +fn index_struct_different_fields(f: &Foo<'_>) { + // ok, different fields + let _ = f.v[0] + f.v2[1]; } fn main() {} diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.stderr b/tests/ui/missing_asserts_for_indexing_unfixable.stderr index c18620f105de..a26524d9a11c 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.stderr +++ b/tests/ui/missing_asserts_for_indexing_unfixable.stderr @@ -1,32 +1,32 @@ error: indexing into a slice multiple times without an `assert` - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:5 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v.len() > 4);` note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:5 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:12 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:19 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:26 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:6:33 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ @@ -34,16 +34,17 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings` error: indexing into a slice multiple times without an `assert` - --> $DIR/missing_asserts_for_indexing_unfixable.rs:11:13 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13 | LL | let _ = v[0]; | _____________^ +LL | | LL | | let _ = v[1..4]; | |___________________^ | = help: consider asserting the length before indexing: `assert!(v.len() > 3);` note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:11:13 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13 | LL | let _ = v[0]; | ^^^^ @@ -55,17 +56,18 @@ LL | let _ = v[1..4]; = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> $DIR/missing_asserts_for_indexing_unfixable.rs:17:13 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13 | LL | let a = v[0]; | _____________^ +LL | | LL | | let b = v[1]; LL | | let c = v[2]; | |________________^ | = help: consider asserting the length before indexing: `assert!(v.len() > 2);` note: slice indexed here - --> $DIR/missing_asserts_for_indexing_unfixable.rs:17:13 + --> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13 | LL | let a = v[0]; | ^^^^