rust-lang / rust-lang/rust-clippy
`indexing_slicing` should not trigger if the `get` method expects a different type
Open
@borngraced is already working on this.
Since Jan 13, 2026.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
As implemented in #12488, the indexing_slicing lint checks if there's a get method before suggesting using it. However, it doesn't check if that method can be used with the type being used as the index.
Lint Name
indexing_slicing
Reproducer
I tried this code (simplified from the linearize docs):
use linearize::{Linearize, static_map};
#[derive(Linearize)]
enum Keys {
A,
B,
}
fn main() {
let map = static_map! {
Keys::A => "a",
Keys::B => "b",
};
assert_eq!(map[Keys::A], "a");
}
I saw this happen:
= help: consider using `.get(n)` or `.get_mut(n)` instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#indexing_slicing
This is because StaticMap<Keys, &str> derefs to [&str], which has a get(usize) method. However, this cannot be used to index by something of type Keys, so I expected the lint not to trigger.
Version
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.