-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Description
Summary
When there is an assert_eq! that doesn't cover the highest index, the suggestion switches to assert! instead
Reproducer
I tried this code:
#![warn(clippy::missing_asserts_for_indexing)]
#![allow(unused)]
fn foo(v: &[i32]) {
assert_eq!(v.len(), 2);
let _ = v[0] + v[1] + v[2];
}I expected to see this happen:
warning: indexing into a slice multiple times with an `assert` that does not cover the highest index
--> src/main.rs:7:13
|
5 | assert_eq!(v.len(), 2);
| ---------------------- help: provide the highest index that is indexed with: `assert_eq!(v.len(), 3)`
|
Instead, this happened:
warning: indexing into a slice multiple times with an `assert` that does not cover the highest index
--> src/main.rs:7:13
|
5 | assert_eq!(v.len(), 2);
| ---------------------- help: provide the highest index that is indexed with: `assert!(v.len() == 3)`
|
Version
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages