We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
manual_memcpy
[..N]
[T; N]
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.
dest[..4].copy_from_slice(&src[..4]);
dest[..4]
dest
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.
src[..4]
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
No response
The text was updated successfully, but these errors were encountered:
@rustbot claim
Sorry, something went wrong.
ca8f33e
granddaifuku
Successfully merging a pull request may close this issue.
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:
Clippy suggests
dest[..4].copy_from_slice(&src[..4]);
, but thedest[..4]
is unnecessary asdest
as a compile-time known length of4
.The same happens when reversing the roles with:
The suggestion is the same but now the
src[..4]
slicing is unnecessary.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: