rust-lang / rust-lang/rust-clippy
indexing_slicing not warning about slicing when the type is a generic array returned from a generic function
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Sample Code: go to https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b and run clippy.
#![warn(clippy::indexing_slicing)]
fn foo<const X: usize, Y: Fn(&[u8]) -> [u8; X]>(a: &mut [u8], y: Y) {
let b = y(a);
a[0..].copy_from_slice(b[0..]);
}
clippy will warn for the a[0..] slice , but not for the &b[0..] slice
Lint Name
indexing_slicing
Reproducer
Run clippy on the code from this sample: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b
#![warn(clippy::indexing_slicing)]
fn foo<const X: usize, Y: Fn(&[u8]) -> [u8; X]>(a: &mut [u8], y: Y) {
let b = y(a);
a[0..].copy_from_slice(b[0..]);
}
I expected to see this happen: clippy should be able to detect the second slice on b and warn about it
Instead, this happened: clippy does not warn about the second slice on b
Version
Clippy version: 0.1.68 (2023-01-18 333ee6c)
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.
Research direction
Start by running Clippy with the reproducer and the indexing_slicing lint enabled, comparing the warnings for the slice on a and the slice on b. Trace the indexing_slicing lint's handling of slices from generic function results, then add coverage showing that b[0..] also produces a warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100