Skip to content

Commit 774e82a

Browse files
committed
Add the tests for manual_memcpy with loop counters
1 parent d9a88be commit 774e82a

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

tests/ui/manual_memcpy.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,60 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
115115
}
116116
}
117117

118+
#[allow(clippy::needless_range_loop, clippy::explicit_counter_loop)]
119+
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
120+
let mut count = 0;
121+
for i in 3..src.len() {
122+
dst[i] = src[count];
123+
count += 1;
124+
}
125+
126+
let mut count = 0;
127+
for i in 3..src.len() {
128+
dst[count] = src[i];
129+
count += 1;
130+
}
131+
132+
let mut count = 3;
133+
for i in 0..src.len() {
134+
dst[count] = src[i];
135+
count += 1;
136+
}
137+
138+
let mut count = 3;
139+
for i in 0..src.len() {
140+
dst[i] = src[count];
141+
count += 1;
142+
}
143+
144+
let mut count = 0;
145+
for i in 3..(3 + src.len()) {
146+
dst[i] = src[count];
147+
count += 1;
148+
}
149+
150+
let mut count = 3;
151+
for i in 5..src.len() {
152+
dst[i] = src[count - 2];
153+
count += 1;
154+
}
155+
156+
let mut count = 5;
157+
for i in 3..10 {
158+
dst[i] = src[count];
159+
count += 1;
160+
}
161+
162+
let mut count = 3;
163+
let mut count = 30;
164+
for i in 0..src.len() {
165+
dst[count] = src[i];
166+
dst2[count] = src[i];
167+
count += 1;
168+
count += 1;
169+
}
170+
}
171+
118172
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]
119173
pub fn manual_clone(src: &[String], dst: &mut [String]) {
120174
for i in 0..src.len() {

tests/ui/manual_memcpy.stderr

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error: it looks like you're manually copying between slices
1616
--> $DIR/manual_memcpy.rs:17:14
1717
|
1818
LL | for i in 0..src.len() {
19-
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..])`
19+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..(src.len() + 10)])`
2020

2121
error: it looks like you're manually copying between slices
2222
--> $DIR/manual_memcpy.rs:22:14
@@ -79,10 +79,64 @@ LL | for i in 0..0 {
7979
| ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
8080

8181
error: it looks like you're manually copying between slices
82-
--> $DIR/manual_memcpy.rs:120:14
82+
--> $DIR/manual_memcpy.rs:121:14
83+
|
84+
LL | for i in 3..src.len() {
85+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)])`
86+
87+
error: it looks like you're manually copying between slices
88+
--> $DIR/manual_memcpy.rs:127:14
89+
|
90+
LL | for i in 3..src.len() {
91+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..])`
92+
93+
error: it looks like you're manually copying between slices
94+
--> $DIR/manual_memcpy.rs:133:14
95+
|
96+
LL | for i in 0..src.len() {
97+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..])`
98+
99+
error: it looks like you're manually copying between slices
100+
--> $DIR/manual_memcpy.rs:139:14
101+
|
102+
LL | for i in 0..src.len() {
103+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)])`
104+
105+
error: it looks like you're manually copying between slices
106+
--> $DIR/manual_memcpy.rs:145:14
107+
|
108+
LL | for i in 3..(3 + src.len()) {
109+
| ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..((3 + src.len()) - 3)])`
110+
111+
error: it looks like you're manually copying between slices
112+
--> $DIR/manual_memcpy.rs:151:14
113+
|
114+
LL | for i in 5..src.len() {
115+
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)])`
116+
117+
error: it looks like you're manually copying between slices
118+
--> $DIR/manual_memcpy.rs:157:14
119+
|
120+
LL | for i in 3..10 {
121+
| ^^^^^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)])`
122+
123+
error: it looks like you're manually copying between slices
124+
--> $DIR/manual_memcpy.rs:164:14
125+
|
126+
LL | for i in 0..src.len() {
127+
| ^^^^^^^^^^^^
128+
|
129+
help: try replacing the loop by
130+
|
131+
LL | for i in dst[3..(src.len() + 3)].clone_from_slice(&src[..])
132+
LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]) {
133+
|
134+
135+
error: it looks like you're manually copying between slices
136+
--> $DIR/manual_memcpy.rs:174:14
83137
|
84138
LL | for i in 0..src.len() {
85139
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
86140

87-
error: aborting due to 13 previous errors
141+
error: aborting due to 21 previous errors
88142

0 commit comments

Comments
 (0)