mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
Add the tests for manual_memcpy
with loop counters
This commit is contained in:
parent
d9a88be0b0
commit
774e82a566
2 changed files with 111 additions and 3 deletions
|
@ -115,6 +115,60 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_range_loop, clippy::explicit_counter_loop)]
|
||||
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
|
||||
let mut count = 0;
|
||||
for i in 3..src.len() {
|
||||
dst[i] = src[count];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 0;
|
||||
for i in 3..src.len() {
|
||||
dst[count] = src[i];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 3;
|
||||
for i in 0..src.len() {
|
||||
dst[count] = src[i];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 3;
|
||||
for i in 0..src.len() {
|
||||
dst[i] = src[count];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 0;
|
||||
for i in 3..(3 + src.len()) {
|
||||
dst[i] = src[count];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 3;
|
||||
for i in 5..src.len() {
|
||||
dst[i] = src[count - 2];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 5;
|
||||
for i in 3..10 {
|
||||
dst[i] = src[count];
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut count = 3;
|
||||
let mut count = 30;
|
||||
for i in 0..src.len() {
|
||||
dst[count] = src[i];
|
||||
dst2[count] = src[i];
|
||||
count += 1;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]
|
||||
pub fn manual_clone(src: &[String], dst: &mut [String]) {
|
||||
for i in 0..src.len() {
|
||||
|
|
|
@ -16,7 +16,7 @@ error: it looks like you're manually copying between slices
|
|||
--> $DIR/manual_memcpy.rs:17:14
|
||||
|
|
||||
LL | for i in 0..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..])`
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..(src.len() + 10)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:22:14
|
||||
|
@ -79,10 +79,64 @@ LL | for i in 0..0 {
|
|||
| ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:120:14
|
||||
--> $DIR/manual_memcpy.rs:121:14
|
||||
|
|
||||
LL | for i in 3..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:127:14
|
||||
|
|
||||
LL | for i in 3..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:133:14
|
||||
|
|
||||
LL | for i in 0..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:139:14
|
||||
|
|
||||
LL | for i in 0..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:145:14
|
||||
|
|
||||
LL | for i in 3..(3 + src.len()) {
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..((3 + src.len()) - 3)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:151:14
|
||||
|
|
||||
LL | for i in 5..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:157:14
|
||||
|
|
||||
LL | for i in 3..10 {
|
||||
| ^^^^^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)])`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:164:14
|
||||
|
|
||||
LL | for i in 0..src.len() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: try replacing the loop by
|
||||
|
|
||||
LL | for i in dst[3..(src.len() + 3)].clone_from_slice(&src[..])
|
||||
LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]) {
|
||||
|
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/manual_memcpy.rs:174:14
|
||||
|
|
||||
LL | for i in 0..src.len() {
|
||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue