Skip to content

Commit 062db10

Browse files
committed
Add manual_memcpy_test for VecDeque
1 parent 3925def commit 062db10

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/ui/manual_memcpy/without_loop_counters.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
113113
for i in 0.. {
114114
dst[i] = src[i];
115115
}
116+
117+
// VecDeque - ideally this would work, but would require something like `range_as_slices`
118+
let mut dst = std::collections::VecDeque::from_iter([0; 5]);
119+
let src = std::collections::VecDeque::from_iter([0, 1, 2, 3, 4]);
120+
for i in 0..dst.len() {
121+
dst[i] = src[i];
122+
}
123+
let src = vec![0, 1, 2, 3, 4];
124+
for i in 0..dst.len() {
125+
dst[i] = src[i];
126+
}
116127
}
117128

118129
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]

tests/ui/manual_memcpy/without_loop_counters.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ LL | | }
104104
| |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);`
105105

106106
error: it looks like you're manually copying between slices
107-
--> $DIR/without_loop_counters.rs:120:5
107+
--> $DIR/without_loop_counters.rs:131:5
108108
|
109109
LL | / for i in 0..src.len() {
110110
LL | | dst[i] = src[i].clone();

0 commit comments

Comments
 (0)