Add manual_memcpy_test for VecDeque

This commit is contained in:
Jason Newcomb 2022-01-12 12:33:47 -05:00
parent 3925def9cf
commit 062db10c12
2 changed files with 12 additions and 1 deletions

View File

@ -113,6 +113,17 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
for i in 0.. {
dst[i] = src[i];
}
// VecDeque - ideally this would work, but would require something like `range_as_slices`
let mut dst = std::collections::VecDeque::from_iter([0; 5]);
let src = std::collections::VecDeque::from_iter([0, 1, 2, 3, 4]);
for i in 0..dst.len() {
dst[i] = src[i];
}
let src = vec![0, 1, 2, 3, 4];
for i in 0..dst.len() {
dst[i] = src[i];
}
}
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]

View File

@ -104,7 +104,7 @@ LL | | }
| |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);`
error: it looks like you're manually copying between slices
--> $DIR/without_loop_counters.rs:120:5
--> $DIR/without_loop_counters.rs:131:5
|
LL | / for i in 0..src.len() {
LL | | dst[i] = src[i].clone();