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

manual_memcpy suggest slicing array when not necessary #11689

Closed
sosthene-nitrokey opened this issue Oct 20, 2023 · 1 comment · Fixed by #11778
Closed

manual_memcpy suggest slicing array when not necessary #11689

sosthene-nitrokey opened this issue Oct 20, 2023 · 1 comment · Fixed by #11778
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@sosthene-nitrokey
Copy link

sosthene-nitrokey commented Oct 20, 2023

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

@sosthene-nitrokey sosthene-nitrokey added the C-bug Category: Clippy is not doing the correct thing label Oct 20, 2023
@granddaifuku
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
2 participants