about summary refs log tree commit diff
diff options
context:
space:
mode:
authorrail <12975677+rail-rain@users.noreply.github.com>2020-09-28 02:43:45 +1300
committerrail <12975677+rail-rain@users.noreply.github.com>2020-09-28 02:43:45 +1300
commitec94bd6cb45e337fd10ca19fadb9a71ecb67db5f (patch)
treeacfff5a47216e1590cc8e9ca35738abd9adc3d9e
parent9725f00f4dd089b875a5d5306ff906494e041f38 (diff)
downloadrust-ec94bd6cb45e337fd10ca19fadb9a71ecb67db5f.tar.gz
rust-ec94bd6cb45e337fd10ca19fadb9a71ecb67db5f.zip
split up the `manual_memcpy` test
-rw-r--r--tests/ui/manual_memcpy/with_loop_counters.rs64
-rw-r--r--tests/ui/manual_memcpy/with_loop_counters.stderr93
-rw-r--r--tests/ui/manual_memcpy/without_loop_counters.rs (renamed from tests/ui/manual_memcpy.rs)61
-rw-r--r--tests/ui/manual_memcpy/without_loop_counters.stderr (renamed from tests/ui/manual_memcpy.stderr)117
4 files changed, 171 insertions, 164 deletions
diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs
new file mode 100644
index 00000000000..a49ba9eb10a
--- /dev/null
+++ b/tests/ui/manual_memcpy/with_loop_counters.rs
@@ -0,0 +1,64 @@
+#![warn(clippy::needless_range_loop, clippy::manual_memcpy)]
+
+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 count2 = 30;
+    for i in 0..src.len() {
+        dst[count] = src[i];
+        dst2[count2] = src[i];
+        count += 1;
+        count2 += 1;
+    }
+
+    // make sure parentheses are added properly to bitwise operators, which have lower precedence than
+    // arithmetric ones
+    let mut count = 0 << 1;
+    for i in 0..1 << 1 {
+        dst[count] = src[i + 2];
+        count += 1;
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr
new file mode 100644
index 00000000000..24393ad9b4d
--- /dev/null
+++ b/tests/ui/manual_memcpy/with_loop_counters.stderr
@@ -0,0 +1,93 @@
+error: it looks like you're manually copying between slices
+  --> $DIR/with_loop_counters.rs:5:5
+   |
+LL | /     for i in 3..src.len() {
+LL | |         dst[i] = src[count];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)]);`
+   |
+   = note: `-D clippy::manual-memcpy` implied by `-D warnings`
+
+error: it looks like you're manually copying between slices
+  --> $DIR/with_loop_counters.rs:11:5
+   |
+LL | /     for i in 3..src.len() {
+LL | |         dst[count] = src[i];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:17:5
+   |
+LL | /     for i in 0..src.len() {
+LL | |         dst[count] = src[i];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:23:5
+   |
+LL | /     for i in 0..src.len() {
+LL | |         dst[i] = src[count];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:29:5
+   |
+LL | /     for i in 3..(3 + src.len()) {
+LL | |         dst[i] = src[count];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:35:5
+   |
+LL | /     for i in 5..src.len() {
+LL | |         dst[i] = src[count - 2];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:41:5
+   |
+LL | /     for i in 3..10 {
+LL | |         dst[i] = src[count];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ 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/with_loop_counters.rs:48:5
+   |
+LL | /     for i in 0..src.len() {
+LL | |         dst[count] = src[i];
+LL | |         dst2[count2] = src[i];
+LL | |         count += 1;
+LL | |         count2 += 1;
+LL | |     }
+   | |_____^
+   |
+help: try replacing the loop by
+   |
+LL |     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/with_loop_counters.rs:58:5
+   |
+LL | /     for i in 0..1 << 1 {
+LL | |         dst[count] = src[i + 2];
+LL | |         count += 1;
+LL | |     }
+   | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)]);`
+
+error: aborting due to 9 previous errors
+
diff --git a/tests/ui/manual_memcpy.rs b/tests/ui/manual_memcpy/without_loop_counters.rs
index 84758275dd7..0083f94798f 100644
--- a/tests/ui/manual_memcpy.rs
+++ b/tests/ui/manual_memcpy/without_loop_counters.rs
@@ -115,67 +115,6 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
     }
 }
 
-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 count2 = 30;
-    for i in 0..src.len() {
-        dst[count] = src[i];
-        dst2[count2] = src[i];
-        count += 1;
-        count2 += 1;
-    }
-
-    // make sure parentheses are added properly to bitwise operators, which have lower precedence than
-    // arithmetric ones
-    let mut count = 0 << 1;
-    for i in 0..1 << 1 {
-        dst[count] = src[i + 2];
-        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() {
diff --git a/tests/ui/manual_memcpy.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr
index db62ed90d97..54b966f6e54 100644
--- a/tests/ui/manual_memcpy.stderr
+++ b/tests/ui/manual_memcpy/without_loop_counters.stderr
@@ -1,5 +1,5 @@
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:7:5
+  --> $DIR/without_loop_counters.rs:7:5
    |
 LL | /     for i in 0..src.len() {
 LL | |         dst[i] = src[i];
@@ -9,7 +9,7 @@ LL | |     }
    = note: `-D clippy::manual-memcpy` implied by `-D warnings`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:12:5
+  --> $DIR/without_loop_counters.rs:12:5
    |
 LL | /     for i in 0..src.len() {
 LL | |         dst[i + 10] = src[i];
@@ -17,7 +17,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].clone_from_slice(&src[..]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:17:5
+  --> $DIR/without_loop_counters.rs:17:5
    |
 LL | /     for i in 0..src.len() {
 LL | |         dst[i] = src[i + 10];
@@ -25,7 +25,7 @@ LL | |     }
    | |_____^ 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:5
+  --> $DIR/without_loop_counters.rs:22:5
    |
 LL | /     for i in 11..src.len() {
 LL | |         dst[i] = src[i - 10];
@@ -33,7 +33,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[11..src.len()].clone_from_slice(&src[(11 - 10)..(src.len() - 10)]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:27:5
+  --> $DIR/without_loop_counters.rs:27:5
    |
 LL | /     for i in 0..dst.len() {
 LL | |         dst[i] = src[i];
@@ -41,7 +41,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst.clone_from_slice(&src[..dst.len()]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:40:5
+  --> $DIR/without_loop_counters.rs:40:5
    |
 LL | /     for i in 10..256 {
 LL | |         dst[i] = src[i - 5];
@@ -56,7 +56,7 @@ LL |     dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256]);
    |
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:52:5
+  --> $DIR/without_loop_counters.rs:52:5
    |
 LL | /     for i in 10..LOOP_OFFSET {
 LL | |         dst[i + LOOP_OFFSET] = src[i - some_var];
@@ -64,7 +64,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].clone_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:65:5
+  --> $DIR/without_loop_counters.rs:65:5
    |
 LL | /     for i in 0..src_vec.len() {
 LL | |         dst_vec[i] = src_vec[i];
@@ -72,7 +72,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].clone_from_slice(&src_vec[..]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:94:5
+  --> $DIR/without_loop_counters.rs:94:5
    |
 LL | /     for i in from..from + src.len() {
 LL | |         dst[i] = src[i - from];
@@ -80,7 +80,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[from..(from + src.len())].clone_from_slice(&src[..(from + src.len() - from)]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:98:5
+  --> $DIR/without_loop_counters.rs:98:5
    |
 LL | /     for i in from..from + 3 {
 LL | |         dst[i] = src[i - from];
@@ -88,7 +88,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[from..(from + 3)].clone_from_slice(&src[..(from + 3 - from)]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:103:5
+  --> $DIR/without_loop_counters.rs:103:5
    |
 LL | /     for i in 0..5 {
 LL | |         dst[i - 0] = src[i];
@@ -96,7 +96,7 @@ LL | |     }
    | |_____^ help: try replacing the loop by: `dst[..5].clone_from_slice(&src[..5]);`
 
 error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:108:5
+  --> $DIR/without_loop_counters.rs:108:5
    |
 LL | /     for i in 0..0 {
 LL | |         dst[i] = src[i];
@@ -104,101 +104,12 @@ LL | |     }
    | |_____^ 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:5
-   |
-LL | /     for i in 3..src.len() {
-LL | |         dst[i] = src[count];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:126:5
-   |
-LL | /     for i in 3..src.len() {
-LL | |         dst[count] = src[i];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:132:5
-   |
-LL | /     for i in 0..src.len() {
-LL | |         dst[count] = src[i];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:138:5
-   |
-LL | /     for i in 0..src.len() {
-LL | |         dst[i] = src[count];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:144:5
-   |
-LL | /     for i in 3..(3 + src.len()) {
-LL | |         dst[i] = src[count];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:150:5
-   |
-LL | /     for i in 5..src.len() {
-LL | |         dst[i] = src[count - 2];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:156:5
-   |
-LL | /     for i in 3..10 {
-LL | |         dst[i] = src[count];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ 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:163:5
-   |
-LL | /     for i in 0..src.len() {
-LL | |         dst[count] = src[i];
-LL | |         dst2[count2] = src[i];
-LL | |         count += 1;
-LL | |         count2 += 1;
-LL | |     }
-   | |_____^
-   |
-help: try replacing the loop by
-   |
-LL |     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:173:5
-   |
-LL | /     for i in 0..1 << 1 {
-LL | |         dst[count] = src[i + 2];
-LL | |         count += 1;
-LL | |     }
-   | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)]);`
-
-error: it looks like you're manually copying between slices
-  --> $DIR/manual_memcpy.rs:181:5
+  --> $DIR/without_loop_counters.rs:120:5
    |
 LL | /     for i in 0..src.len() {
 LL | |         dst[i] = src[i].clone();
 LL | |     }
    | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);`
 
-error: aborting due to 22 previous errors
+error: aborting due to 13 previous errors