about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2020-07-25 01:14:10 +0000
committerLzu Tao <taolzu@gmail.com>2020-08-08 10:38:49 +0000
commitef50477c786016bf1712a34155d067b407e35cc0 (patch)
tree9286af7fa7e9a5b8f07f48a3d29c5fa7b280a173
parent0a8d4ce055d40bb4897d1cd5c110174ede8ed505 (diff)
downloadrust-ef50477c786016bf1712a34155d067b407e35cc0.tar.gz
rust-ef50477c786016bf1712a34155d067b407e35cc0.zip
Add a regression test for match guard
Unlike if condition, match guard accepts struct literal.
-rw-r--r--src/test/ui/parser/struct-literal-in-match-guard.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/ui/parser/struct-literal-in-match-guard.rs b/src/test/ui/parser/struct-literal-in-match-guard.rs
new file mode 100644
index 00000000000..bf0551b5c97
--- /dev/null
+++ b/src/test/ui/parser/struct-literal-in-match-guard.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+// Unlike `if` condition, `match` guards accept struct literals.
+// This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>.
+
+#[derive(PartialEq)]
+struct Foo {
+    x: isize,
+}
+
+fn foo(f: Foo) {
+    match () {
+        () if f == Foo { x: 42 } => {}
+        _ => {}
+    }
+}
+
+fn main() {}