Skip to content

Commit ec94bd6

Browse files
committed
split up the manual_memcpy test
1 parent 9725f00 commit ec94bd6

File tree

4 files changed

+171
-164
lines changed

4 files changed

+171
-164
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#![warn(clippy::needless_range_loop, clippy::manual_memcpy)]
2+
3+
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
4+
let mut count = 0;
5+
for i in 3..src.len() {
6+
dst[i] = src[count];
7+
count += 1;
8+
}
9+
10+
let mut count = 0;
11+
for i in 3..src.len() {
12+
dst[count] = src[i];
13+
count += 1;
14+
}
15+
16+
let mut count = 3;
17+
for i in 0..src.len() {
18+
dst[count] = src[i];
19+
count += 1;
20+
}
21+
22+
let mut count = 3;
23+
for i in 0..src.len() {
24+
dst[i] = src[count];
25+
count += 1;
26+
}
27+
28+
let mut count = 0;
29+
for i in 3..(3 + src.len()) {
30+
dst[i] = src[count];
31+
count += 1;
32+
}
33+
34+
let mut count = 3;
35+
for i in 5..src.len() {
36+
dst[i] = src[count - 2];
37+
count += 1;
38+
}
39+
40+
let mut count = 5;
41+
for i in 3..10 {
42+
dst[i] = src[count];
43+
count += 1;
44+
}
45+
46+
let mut count = 3;
47+
let mut count2 = 30;
48+
for i in 0..src.len() {
49+
dst[count] = src[i];
50+
dst2[count2] = src[i];
51+
count += 1;
52+
count2 += 1;
53+
}
54+
55+
// make sure parentheses are added properly to bitwise operators, which have lower precedence than
56+
// arithmetric ones
57+
let mut count = 0 << 1;
58+
for i in 0..1 << 1 {
59+
dst[count] = src[i + 2];
60+
count += 1;
61+
}
62+
}
63+
64+
fn main() {}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
error: it looks like you're manually copying between slices
2+
--> $DIR/with_loop_counters.rs:5:5
3+
|
4+
LL | / for i in 3..src.len() {
5+
LL | | dst[i] = src[count];
6+
LL | | count += 1;
7+
LL | | }
8+
| |_____^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)]);`
9+
|
10+
= note: `-D clippy::manual-memcpy` implied by `-D warnings`
11+
12+
error: it looks like you're manually copying between slices
13+
--> $DIR/with_loop_counters.rs:11:5
14+
|
15+
LL | / for i in 3..src.len() {
16+
LL | | dst[count] = src[i];
17+
LL | | count += 1;
18+
LL | | }
19+
| |_____^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..]);`
20+
21+
error: it looks like you're manually copying between slices
22+
--> $DIR/with_loop_counters.rs:17:5
23+
|
24+
LL | / for i in 0..src.len() {
25+
LL | | dst[count] = src[i];
26+
LL | | count += 1;
27+
LL | | }
28+
| |_____^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..]);`
29+
30+
error: it looks like you're manually copying between slices
31+
--> $DIR/with_loop_counters.rs:23:5
32+
|
33+
LL | / for i in 0..src.len() {
34+
LL | | dst[i] = src[count];
35+
LL | | count += 1;
36+
LL | | }
37+
| |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)]);`
38+
39+
error: it looks like you're manually copying between slices
40+
--> $DIR/with_loop_counters.rs:29:5
41+
|
42+
LL | / for i in 3..(3 + src.len()) {
43+
LL | | dst[i] = src[count];
44+
LL | | count += 1;
45+
LL | | }
46+
| |_____^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)]);`
47+
48+
error: it looks like you're manually copying between slices
49+
--> $DIR/with_loop_counters.rs:35:5
50+
|
51+
LL | / for i in 5..src.len() {
52+
LL | | dst[i] = src[count - 2];
53+
LL | | count += 1;
54+
LL | | }
55+
| |_____^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)]);`
56+
57+
error: it looks like you're manually copying between slices
58+
--> $DIR/with_loop_counters.rs:41:5
59+
|
60+
LL | / for i in 3..10 {
61+
LL | | dst[i] = src[count];
62+
LL | | count += 1;
63+
LL | | }
64+
| |_____^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)]);`
65+
66+
error: it looks like you're manually copying between slices
67+
--> $DIR/with_loop_counters.rs:48:5
68+
|
69+
LL | / for i in 0..src.len() {
70+
LL | | dst[count] = src[i];
71+
LL | | dst2[count2] = src[i];
72+
LL | | count += 1;
73+
LL | | count2 += 1;
74+
LL | | }
75+
| |_____^
76+
|
77+
help: try replacing the loop by
78+
|
79+
LL | dst[3..(src.len() + 3)].clone_from_slice(&src[..]);
80+
LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]);
81+
|
82+
83+
error: it looks like you're manually copying between slices
84+
--> $DIR/with_loop_counters.rs:58:5
85+
|
86+
LL | / for i in 0..1 << 1 {
87+
LL | | dst[count] = src[i + 2];
88+
LL | | count += 1;
89+
LL | | }
90+
| |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)]);`
91+
92+
error: aborting due to 9 previous errors
93+

tests/ui/manual_memcpy.rs renamed to tests/ui/manual_memcpy/without_loop_counters.rs

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

118-
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
119-
let mut count = 0;
120-
for i in 3..src.len() {
121-
dst[i] = src[count];
122-
count += 1;
123-
}
124-
125-
let mut count = 0;
126-
for i in 3..src.len() {
127-
dst[count] = src[i];
128-
count += 1;
129-
}
130-
131-
let mut count = 3;
132-
for i in 0..src.len() {
133-
dst[count] = src[i];
134-
count += 1;
135-
}
136-
137-
let mut count = 3;
138-
for i in 0..src.len() {
139-
dst[i] = src[count];
140-
count += 1;
141-
}
142-
143-
let mut count = 0;
144-
for i in 3..(3 + src.len()) {
145-
dst[i] = src[count];
146-
count += 1;
147-
}
148-
149-
let mut count = 3;
150-
for i in 5..src.len() {
151-
dst[i] = src[count - 2];
152-
count += 1;
153-
}
154-
155-
let mut count = 5;
156-
for i in 3..10 {
157-
dst[i] = src[count];
158-
count += 1;
159-
}
160-
161-
let mut count = 3;
162-
let mut count2 = 30;
163-
for i in 0..src.len() {
164-
dst[count] = src[i];
165-
dst2[count2] = src[i];
166-
count += 1;
167-
count2 += 1;
168-
}
169-
170-
// make sure parentheses are added properly to bitwise operators, which have lower precedence than
171-
// arithmetric ones
172-
let mut count = 0 << 1;
173-
for i in 0..1 << 1 {
174-
dst[count] = src[i + 2];
175-
count += 1;
176-
}
177-
}
178-
179118
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]
180119
pub fn manual_clone(src: &[String], dst: &mut [String]) {
181120
for i in 0..src.len() {

0 commit comments

Comments
 (0)