Skip to content

manual_memcpy false positive #9334

Closed
@ViridiFox

Description

@ViridiFox

Summary

Copying the diagonal from a 2d Matrix/Vec to a 1d Vec gives the false positive that it can be replaced by a copy_from_slice.

Lint Name

manual_memcpy

Reproducer

the minimal code:

fn main() {
    let m2d = vec![vec![0; 10]; 10];
    let mut m1d = vec![0; 10];

    for i in 0..10 {
        m1d[i] = m2d[i][i];
    }
}

gives the warning:

warning: it looks like you're manually copying between slices
 --> src/main.rs:5:5
  |
5 | /     for i in 0..10 {
6 | |         m1d[i] = m2d[i][i];
7 | |     }
  | |_____^ help: try replacing the loop by: `m1d[..10].copy_from_slice(&m2d[i][..10]);`
  |
  = note: `#[warn(clippy::manual_memcpy)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy```

Version

rustc 1.65.0-nightly (d394408fb 2022-08-07)
binary: rustc
commit-hash: d394408fb38c4de61f765a3ed5189d2731a1da91
commit-date: 2022-08-07
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 14.0.6

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions