Skip to content

Commit

Permalink
Add manual_memcpy_test for VecDeque
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Jan 12, 2022
1 parent 3925def commit 062db10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/ui/manual_memcpy/without_loop_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_memcpy/without_loop_counters.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 062db10

Please sign in to comment.