Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy::indexing_slicing does not report slicing on &str #13703

Open
link2xt opened this issue Nov 18, 2024 · 2 comments
Open

clippy::indexing_slicing does not report slicing on &str #13703

link2xt opened this issue Nov 18, 2024 · 2 comments
Labels
A-documentation Area: Adding or improving documentation C-bug Category: Clippy is not doing the correct thing

Comments

@link2xt
Copy link

link2xt commented Nov 18, 2024

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)
@link2xt link2xt added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Nov 18, 2024
@y21
Copy link
Member

y21 commented Nov 18, 2024

This is covered by the string_slice lint. If you change the reproducer to use #![warn(clippy::string_slice)] then you should get a warning.

@link2xt
Copy link
Author

link2xt commented Nov 18, 2024

Then this can be treated as documentation issue, indexing_slicing docs should mention string_slice.

@y21 y21 added A-documentation Area: Adding or improving documentation and removed I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants