about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2023-11-27 01:08:39 +0100
committerNadrieril <nadrieril+git@gmail.com>2023-12-02 03:41:37 +0100
commitcaa488b96e65131e4d70f219d5e89008031f9229 (patch)
treea0a55e71028fad7d4b1b2c87fb2142d2f45fb81d
parentbd3a22115fa3b7c572333783cd315c134b48e967 (diff)
downloadrust-caa488b96e65131e4d70f219d5e89008031f9229.tar.gz
rust-caa488b96e65131e4d70f219d5e89008031f9229.zip
Add tests
-rw-r--r--tests/ui/never_patterns/check.rs30
-rw-r--r--tests/ui/never_patterns/check.stderr8
-rw-r--r--tests/ui/parser/match-arm-without-body.rs68
-rw-r--r--tests/ui/parser/match-arm-without-body.stderr122
-rw-r--r--tests/ui/pattern/never_patterns.rs2
5 files changed, 229 insertions, 1 deletions
diff --git a/tests/ui/never_patterns/check.rs b/tests/ui/never_patterns/check.rs
new file mode 100644
index 00000000000..bcc3a760c10
--- /dev/null
+++ b/tests/ui/never_patterns/check.rs
@@ -0,0 +1,30 @@
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+enum Void {}
+
+fn main() {}
+
+macro_rules! never {
+    () => { ! }
+}
+
+fn no_arms_or_guards(x: Void) {
+    match None::<Void> {
+        Some(!) => {}
+        None => {}
+    }
+    match None::<Void> {
+        Some(!) if true,
+        //~^ ERROR expected one of
+        None => {}
+    }
+    match None::<Void> {
+        Some(!) if true => {}
+        None => {}
+    }
+    match None::<Void> {
+        Some(never!()) => {},
+        None => {}
+    }
+}
diff --git a/tests/ui/never_patterns/check.stderr b/tests/ui/never_patterns/check.stderr
new file mode 100644
index 00000000000..d7cdd64840f
--- /dev/null
+++ b/tests/ui/never_patterns/check.stderr
@@ -0,0 +1,8 @@
+error: expected one of `.`, `=>`, `?`, or an operator, found `,`
+  --> $DIR/check.rs:18:24
+   |
+LL |         Some(!) if true,
+   |                        ^ expected one of `.`, `=>`, `?`, or an operator
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/parser/match-arm-without-body.rs b/tests/ui/parser/match-arm-without-body.rs
new file mode 100644
index 00000000000..5f009c7a355
--- /dev/null
+++ b/tests/ui/parser/match-arm-without-body.rs
@@ -0,0 +1,68 @@
+macro_rules! pat {
+    () => { Some(_) }
+}
+
+fn main() {
+    match Some(false) {
+        Some(_)
+    }
+    //~^ ERROR expected one of
+    match Some(false) {
+        Some(_)
+        _ => {}
+        //~^ ERROR expected one of
+    }
+    match Some(false) {
+        Some(_),
+        //~^ ERROR unexpected `,` in pattern
+        //~| HELP try adding parentheses to match on a tuple
+        //~| HELP or a vertical bar to match on multiple alternatives
+    }
+    match Some(false) {
+        Some(_),
+        //~^ ERROR unexpected `,` in pattern
+        //~| HELP try adding parentheses to match on a tuple
+        //~| HELP or a vertical bar to match on multiple alternatives
+        _ => {}
+    }
+    match Some(false) {
+        Some(_) if true
+    }
+    //~^ ERROR expected one of
+    match Some(false) {
+        Some(_) if true
+        _ => {}
+        //~^ ERROR expected one of
+    }
+    match Some(false) {
+        Some(_) if true,
+        //~^ ERROR expected one of
+    }
+    match Some(false) {
+        Some(_) if true,
+        //~^ ERROR expected one of
+        _ => {}
+    }
+    match Some(false) {
+        pat!()
+    }
+    //~^ ERROR expected one of
+    match Some(false) {
+        pat!(),
+        //~^ ERROR unexpected `,` in pattern
+    }
+    match Some(false) {
+        pat!() if true,
+        //~^ ERROR expected one of
+    }
+    match Some(false) {
+        pat!()
+        _ => {}
+        //~^ ERROR expected one of
+    }
+    match Some(false) {
+        pat!(),
+        //~^ ERROR unexpected `,` in pattern
+        _ => {}
+    }
+}
diff --git a/tests/ui/parser/match-arm-without-body.stderr b/tests/ui/parser/match-arm-without-body.stderr
new file mode 100644
index 00000000000..210007628db
--- /dev/null
+++ b/tests/ui/parser/match-arm-without-body.stderr
@@ -0,0 +1,122 @@
+error: expected one of `=>`, `if`, or `|`, found `}`
+  --> $DIR/match-arm-without-body.rs:8:5
+   |
+LL |         Some(_)
+   |                - expected one of `=>`, `if`, or `|`
+LL |     }
+   |     ^ unexpected token
+
+error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
+  --> $DIR/match-arm-without-body.rs:12:9
+   |
+LL |         Some(_)
+   |                - expected one of `=>`, `if`, or `|`
+LL |         _ => {}
+   |         ^ unexpected token
+
+error: unexpected `,` in pattern
+  --> $DIR/match-arm-without-body.rs:16:16
+   |
+LL |         Some(_),
+   |                ^
+   |
+help: try adding parentheses to match on a tuple...
+   |
+LL |         (Some(_),)
+   |         +        +
+help: ...or a vertical bar to match on multiple alternatives
+   |
+LL |         Some(_) |
+   |
+
+error: unexpected `,` in pattern
+  --> $DIR/match-arm-without-body.rs:22:16
+   |
+LL |         Some(_),
+   |                ^
+   |
+help: try adding parentheses to match on a tuple...
+   |
+LL ~         (Some(_),
+LL |
+LL |
+LL |
+LL ~         _) => {}
+   |
+help: ...or a vertical bar to match on multiple alternatives
+   |
+LL ~         Some(_) |
+LL +
+LL +
+LL +
+LL ~         _ => {}
+   |
+
+error: expected one of `.`, `=>`, `?`, or an operator, found `}`
+  --> $DIR/match-arm-without-body.rs:30:5
+   |
+LL |         Some(_) if true
+   |                        - expected one of `.`, `=>`, `?`, or an operator
+LL |     }
+   |     ^ unexpected token
+
+error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
+  --> $DIR/match-arm-without-body.rs:34:9
+   |
+LL |         Some(_) if true
+   |                        - expected one of `.`, `=>`, `?`, or an operator
+LL |         _ => {}
+   |         ^ unexpected token
+
+error: expected one of `.`, `=>`, `?`, or an operator, found `,`
+  --> $DIR/match-arm-without-body.rs:38:24
+   |
+LL |         Some(_) if true,
+   |                        ^ expected one of `.`, `=>`, `?`, or an operator
+
+error: expected one of `.`, `=>`, `?`, or an operator, found `,`
+  --> $DIR/match-arm-without-body.rs:42:24
+   |
+LL |         Some(_) if true,
+   |                        ^ expected one of `.`, `=>`, `?`, or an operator
+
+error: expected one of `=>`, `if`, or `|`, found `}`
+  --> $DIR/match-arm-without-body.rs:48:5
+   |
+LL |         pat!()
+   |               - expected one of `=>`, `if`, or `|`
+LL |     }
+   |     ^ unexpected token
+
+error: unexpected `,` in pattern
+  --> $DIR/match-arm-without-body.rs:51:15
+   |
+LL |         pat!(),
+   |               ^
+   |
+   = note: macros cannot expand to match arms
+
+error: expected one of `.`, `=>`, `?`, or an operator, found `,`
+  --> $DIR/match-arm-without-body.rs:55:23
+   |
+LL |         pat!() if true,
+   |                       ^ expected one of `.`, `=>`, `?`, or an operator
+
+error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
+  --> $DIR/match-arm-without-body.rs:60:9
+   |
+LL |         pat!()
+   |               - expected one of `=>`, `if`, or `|`
+LL |         _ => {}
+   |         ^ unexpected token
+
+error: unexpected `,` in pattern
+  --> $DIR/match-arm-without-body.rs:64:15
+   |
+LL |         pat!(),
+   |               ^
+   |
+   = note: macros cannot expand to match arms
+
+error: aborting due to 13 previous errors
+
diff --git a/tests/ui/pattern/never_patterns.rs b/tests/ui/pattern/never_patterns.rs
index e2e17e0e9a7..fdba1b8e087 100644
--- a/tests/ui/pattern/never_patterns.rs
+++ b/tests/ui/pattern/never_patterns.rs
@@ -84,7 +84,7 @@ fn never_and_bindings() {
         //~^ ERROR: is not bound in all patterns
     }
     let (Ok(_x) | Err(&!)) = x;
-        //~^ ERROR: is not bound in all patterns
+    //~^ ERROR: is not bound in all patterns
 
     // FIXME(never_patterns): A never pattern mustn't have bindings.
     match x {