about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-10-18 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-10-19 20:45:43 +0200
commitc97cf7fed7f151e493e08b95ce4f04856974faab (patch)
tree0211d9448dff5d77d7231f0fb319d292be30f4b1 /src
parent1af55d19c7a9189374d89472f97dc119659bb67e (diff)
downloadrust-c97cf7fed7f151e493e08b95ce4f04856974faab.tar.gz
rust-c97cf7fed7f151e493e08b95ce4f04856974faab.zip
Reject closures in patterns
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/consts/closure-structural-match-issue-90013.rs8
-rw-r--r--src/test/ui/pattern/non-structural-match-types.rs14
-rw-r--r--src/test/ui/pattern/non-structural-match-types.stderr14
3 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/consts/closure-structural-match-issue-90013.rs b/src/test/ui/consts/closure-structural-match-issue-90013.rs
new file mode 100644
index 00000000000..7853ee41a90
--- /dev/null
+++ b/src/test/ui/consts/closure-structural-match-issue-90013.rs
@@ -0,0 +1,8 @@
+// Regression test for issue 90013.
+// check-pass
+#![allow(incomplete_features)]
+#![feature(inline_const)]
+
+fn main() {
+    const { || {} };
+}
diff --git a/src/test/ui/pattern/non-structural-match-types.rs b/src/test/ui/pattern/non-structural-match-types.rs
new file mode 100644
index 00000000000..713418fc5b2
--- /dev/null
+++ b/src/test/ui/pattern/non-structural-match-types.rs
@@ -0,0 +1,14 @@
+// edition:2021
+#![allow(incomplete_features)]
+#![allow(unreachable_code)]
+#![feature(const_async_blocks)]
+#![feature(inline_const)]
+
+fn main() {
+    match loop {} {
+        const { || {} } => {}, //~ ERROR cannot be used in patterns
+    }
+    match loop {} {
+        const { async {} } => {}, //~ ERROR cannot be used in patterns
+    }
+}
diff --git a/src/test/ui/pattern/non-structural-match-types.stderr b/src/test/ui/pattern/non-structural-match-types.stderr
new file mode 100644
index 00000000000..91fed81eaef
--- /dev/null
+++ b/src/test/ui/pattern/non-structural-match-types.stderr
@@ -0,0 +1,14 @@
+error: `[closure@$DIR/non-structural-match-types.rs:9:17: 9:22]` cannot be used in patterns
+  --> $DIR/non-structural-match-types.rs:9:9
+   |
+LL |         const { || {} } => {},
+   |         ^^^^^^^^^^^^^^^
+
+error: `impl Future` cannot be used in patterns
+  --> $DIR/non-structural-match-types.rs:12:9
+   |
+LL |         const { async {} } => {},
+   |         ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+