about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGiacomo Stevanato <giaco.stevanato@gmail.com>2021-02-28 21:03:44 +0100
committerGiacomo Stevanato <giaco.stevanato@gmail.com>2021-03-01 08:56:11 +0100
commit3c63f67802c728bd84953c19735fabd8f071c326 (patch)
treef2d6a7cb45a90cbef1e5af565c87e8ce20faf2fa
parent6214ef8a0fd0f3275dc6954198be3ed9d960ac76 (diff)
downloadrust-3c63f67802c728bd84953c19735fabd8f071c326.tar.gz
rust-3c63f67802c728bd84953c19735fabd8f071c326.zip
Add regression test
-rw-r--r--src/test/ui/lint/issue-81314-unused-span-ident.fixed12
-rw-r--r--src/test/ui/lint/issue-81314-unused-span-ident.rs12
-rw-r--r--src/test/ui/lint/issue-81314-unused-span-ident.stderr21
3 files changed, 45 insertions, 0 deletions
diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.fixed b/src/test/ui/lint/issue-81314-unused-span-ident.fixed
new file mode 100644
index 00000000000..aac918f2bc8
--- /dev/null
+++ b/src/test/ui/lint/issue-81314-unused-span-ident.fixed
@@ -0,0 +1,12 @@
+// run-rustfix
+// Regression test for #81314: Unused variable lint should
+// span only the identifier and not the rest of the pattern
+
+#![deny(unused)]
+
+fn main() {
+    let [_rest @ ..] = [1, 2, 3]; //~ ERROR unused variable
+}
+
+pub fn foo([_rest @ ..]: &[i32]) { //~ ERROR unused variable
+}
diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.rs b/src/test/ui/lint/issue-81314-unused-span-ident.rs
new file mode 100644
index 00000000000..78296f4258d
--- /dev/null
+++ b/src/test/ui/lint/issue-81314-unused-span-ident.rs
@@ -0,0 +1,12 @@
+// run-rustfix
+// Regression test for #81314: Unused variable lint should
+// span only the identifier and not the rest of the pattern
+
+#![deny(unused)]
+
+fn main() {
+    let [rest @ ..] = [1, 2, 3]; //~ ERROR unused variable
+}
+
+pub fn foo([rest @ ..]: &[i32]) { //~ ERROR unused variable
+}
diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.stderr b/src/test/ui/lint/issue-81314-unused-span-ident.stderr
new file mode 100644
index 00000000000..519c71e9413
--- /dev/null
+++ b/src/test/ui/lint/issue-81314-unused-span-ident.stderr
@@ -0,0 +1,21 @@
+error: unused variable: `rest`
+  --> $DIR/issue-81314-unused-span-ident.rs:8:10
+   |
+LL |     let [rest @ ..] = [1, 2, 3];
+   |          ^^^^ help: if this is intentional, prefix it with an underscore: `_rest`
+   |
+note: the lint level is defined here
+  --> $DIR/issue-81314-unused-span-ident.rs:5:9
+   |
+LL | #![deny(unused)]
+   |         ^^^^^^
+   = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]`
+
+error: unused variable: `rest`
+  --> $DIR/issue-81314-unused-span-ident.rs:11:13
+   |
+LL | pub fn foo([rest @ ..]: &[i32]) {
+   |             ^^^^ help: if this is intentional, prefix it with an underscore: `_rest`
+
+error: aborting due to 2 previous errors
+