-
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 messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.
Description
I tried this code:
#![warn(clippy::indexing_slicing)]
pub fn f(arr: &[u32; 2]) {
let _a = arr[0];
}I expected to see this happen:
No warning displayed, as arr[0] is known to exist, because arr has 2 elements.
Instead, this happened:
I got the warning:
warning: indexing may panic.
--> src/lib.rs:4:14
|
4 | let _a = arr[0];
| ^^^^^^
|
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::indexing_slicing)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
= help: Consider using `.get(n)` or `.get_mut(n)` instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicingAt first I thought that perhaps arr[0] would use <[u8]>::index and so it could panic and clippy was correct, but when building the assembly, even in debug mode, there is no panic code, and using an invalid index triggers a rustc error about the operation always panicking at runtime, so I believe clippy should also detect when this is valid.
Meta
cargo clippy -V: e.g. clippy 0.0.212 (2020-09-08 5099914)
As this is on the playground, I am unable to run rustc -Vv or provide a backtrace.
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 messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.