rust-lang / rust-lang/rust-clippy
Clippy finds less clear fix for manual_memcpy
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I tried this code:
fn main()
{
let mut block: [u8; 40] = [0; 40];
let type_ext: [u8; 16] = [0; 16];
for i in 24..40 {
block[i] = type_ext[i - 24];
}
}
I expected to see this happen: Clippy finding fix block[24..40].copy_from_slice(&type_ext)
Instead, this happened: Clippy suggests less clear form: block[24..40].clone_from_slice(&type_ext[..(40 - 24)]);
I suppose clippy did not find that type_ext is 16 u8 and not more.
Meta
Rust version (rustc -Vv):
rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0
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 locating the manual_memcpy lint entry point and reproducing the supplied Rust snippet with the reported toolchain. Confirm that the suggested fix can use copy_from_slice with the complete type_ext array, and verify the diagnostic no longer adds an unnecessary slice bound.
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
- Mostly clear
- Newbie friendliness
- 35/100