Skip to content

manual_memcpy should not suggest addition in  #11688

Open

Description

Summary

The manual_memcpy lint makes suggestions that are not always the easiest to read when iterating with a offset.

Reproducer

For example:

    let src: &[u8] = todo!();
    let dest: &mut [u8] = todo!();
    
    for i in 0..4 {
        dest[i] = src[1 + i];
    }

Leads to a suggestion to use instead:

dest[..4].copy_from_slice(&src[1..(4 + 1)]);

Which works, but in this specific case, I would probably manually write:

dest[..4].copy_from_slice(&src[1..][..4]);

Which is more readable. src[1..5] would also make sense but it seems harder to generalize and implement, and introduces a number with a non-obvious source.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions