Skip to content

Clippy finds less clear fix for manual_memcpy #7931

@Yuri6037

Description

@Yuri6037

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions