-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationC-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
indexing_slicing does not report slicing of &str and it breaks.
Lint Name
clippy::indexing_slicing
Reproducer
I tried this code:
#![warn(clippy::indexing_slicing)]
fn main() {
let s = "foobar";
let _ = s[..500];
println!("Hello, world!");
}
I expected clippy to report a warning, but it does not. The code crashes when I run it:
$ cargo run
Compiling clippy-debug v0.1.0 (/home/user/clippy-debug)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Running `target/debug/clippy-debug`
thread 'main' panicked at src/main.rs:5:14:
byte index 500 is out of bounds of `foobar`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Version
$ rustc -Vv
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1
$ cargo clippy --version
clippy 0.1.82 (f6e511e 2024-10-15)
Metadata
Metadata
Assignees
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationC-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing