-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
there's many cases where a vector is clearly infallible but the indexing_slicing lint still complains that it might fall. Would be nice if clippy better recognize cases that are deterministically known to be infallible
Lint Name
indexing_slicing
Reproducer
I tried this code:
fn main() {
let vec = vec();
dbg!(vec[1]);
}
fn vec() -> Vec<i32> {
vec![0, 0, 0]
}I saw this happen:
indexing may panic
consider using `.get(n)` or `.get_mut(n)` instead
for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#indexing_slicing
requested on the command line with `-W clippy::indexing-slicing
I expected to see this happen:
silence
Version
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8
Additional Labels
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have