about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/manual_let_else_match.rs2
-rw-r--r--tests/ui/match_on_vec_items.rs2
-rw-r--r--tests/ui/redundant_rest_pattern.fixed27
-rw-r--r--tests/ui/redundant_rest_pattern.rs27
-rw-r--r--tests/ui/redundant_rest_pattern.stderr40
5 files changed, 96 insertions, 2 deletions
diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs
index 07cd5a53a7c..073094ea789 100644
--- a/tests/ui/manual_let_else_match.rs
+++ b/tests/ui/manual_let_else_match.rs
@@ -1,5 +1,5 @@
 #![allow(unused_braces, unused_variables, dead_code)]
-#![allow(clippy::collapsible_else_if, clippy::let_unit_value)]
+#![allow(clippy::collapsible_else_if, clippy::let_unit_value, clippy::redundant_rest_pattern)]
 #![warn(clippy::manual_let_else)]
 // Ensure that we don't conflict with match -> if let lints
 #![warn(clippy::single_match_else, clippy::single_match)]
diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs
index d82a736963a..fe214904365 100644
--- a/tests/ui/match_on_vec_items.rs
+++ b/tests/ui/match_on_vec_items.rs
@@ -1,5 +1,5 @@
 #![warn(clippy::match_on_vec_items)]
-#![allow(clippy::useless_vec)]
+#![allow(clippy::redundant_rest_pattern, clippy::useless_vec)]
 
 fn match_with_wildcard() {
     let arr = vec![0, 1, 2, 3];
diff --git a/tests/ui/redundant_rest_pattern.fixed b/tests/ui/redundant_rest_pattern.fixed
new file mode 100644
index 00000000000..d9a98622c42
--- /dev/null
+++ b/tests/ui/redundant_rest_pattern.fixed
@@ -0,0 +1,27 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs
+#![allow(irrefutable_let_patterns, unused)]
+#![warn(clippy::redundant_rest_pattern)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn main() {
+    if let a = [()] {}
+    if let ref a = [()] {}
+    if let mut a = [()] {}
+    if let ref mut a = [()] {}
+    let v = vec![()];
+    if let a = &*v {}
+    let s = &[()];
+    if let a = s {}
+    // Don't lint
+    if let [..] = &*v {}
+    if let [a] = &*v {}
+    if let [()] = &*v {}
+    if let [first, rest @ ..] = &*v {}
+    if let a = [()] {}
+    external! {
+        if let [a @ ..] = [()] {}
+    }
+}
diff --git a/tests/ui/redundant_rest_pattern.rs b/tests/ui/redundant_rest_pattern.rs
new file mode 100644
index 00000000000..60a12bfd6fb
--- /dev/null
+++ b/tests/ui/redundant_rest_pattern.rs
@@ -0,0 +1,27 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs
+#![allow(irrefutable_let_patterns, unused)]
+#![warn(clippy::redundant_rest_pattern)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn main() {
+    if let [a @ ..] = [()] {}
+    if let [ref a @ ..] = [()] {}
+    if let [mut a @ ..] = [()] {}
+    if let [ref mut a @ ..] = [()] {}
+    let v = vec![()];
+    if let [a @ ..] = &*v {}
+    let s = &[()];
+    if let [a @ ..] = s {}
+    // Don't lint
+    if let [..] = &*v {}
+    if let [a] = &*v {}
+    if let [()] = &*v {}
+    if let [first, rest @ ..] = &*v {}
+    if let a = [()] {}
+    external! {
+        if let [a @ ..] = [()] {}
+    }
+}
diff --git a/tests/ui/redundant_rest_pattern.stderr b/tests/ui/redundant_rest_pattern.stderr
new file mode 100644
index 00000000000..630909a0a16
--- /dev/null
+++ b/tests/ui/redundant_rest_pattern.stderr
@@ -0,0 +1,40 @@
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:10:12
+   |
+LL |     if let [a @ ..] = [()] {}
+   |            ^^^^^^^^ help: this is better represented with just the binding: `a`
+   |
+   = note: `-D clippy::redundant-rest-pattern` implied by `-D warnings`
+
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:11:12
+   |
+LL |     if let [ref a @ ..] = [()] {}
+   |            ^^^^^^^^^^^^ help: this is better represented with just the binding: `ref a`
+
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:12:12
+   |
+LL |     if let [mut a @ ..] = [()] {}
+   |            ^^^^^^^^^^^^ help: this is better represented with just the binding: `mut a`
+
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:13:12
+   |
+LL |     if let [ref mut a @ ..] = [()] {}
+   |            ^^^^^^^^^^^^^^^^ help: this is better represented with just the binding: `ref mut a`
+
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:15:12
+   |
+LL |     if let [a @ ..] = &*v {}
+   |            ^^^^^^^^ help: this is better represented with just the binding: `a`
+
+error: using a rest pattern to bind an entire slice to a local
+  --> $DIR/redundant_rest_pattern.rs:17:12
+   |
+LL |     if let [a @ ..] = s {}
+   |            ^^^^^^^^ help: this is better represented with just the binding: `a`
+
+error: aborting due to 6 previous errors
+