-
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 thing
Description
Summary
The manual_memcpy
can suggest slicing an array with [..N]
even if the type of the array is [T; N]
, which makes the slicing unnecessary.
Reproducer
I tried this code:
let src: &[u8] = todo!();
let mut dest = [0; 4];
for i in 0..4 {
dest[i] = src[i];
}
Clippy suggests dest[..4].copy_from_slice(&src[..4]);
, but the dest[..4]
is unnecessary as dest
as a compile-time known length of 4
.
The same happens when reversing the roles with:
let dest: &mut [u8] = todo!();
let src = [0; 4];
for i in 0..4 {
dest[i] = src[i];
}
The suggestion is the same but now the src[..4]
slicing is unnecessary.
Version
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing