Closed
Description
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