Skip to content

missing_asserts_for_indexing turns assert_eq! into assert! #16026

@ada4a

Description

@ada4a

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 thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions