From caa488b96e65131e4d70f219d5e89008031f9229 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 27 Nov 2023 01:08:39 +0100 Subject: [PATCH] Add tests --- tests/ui/never_patterns/check.rs | 30 +++++ tests/ui/never_patterns/check.stderr | 8 ++ tests/ui/parser/match-arm-without-body.rs | 68 ++++++++++ tests/ui/parser/match-arm-without-body.stderr | 122 ++++++++++++++++++ tests/ui/pattern/never_patterns.rs | 2 +- 5 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 tests/ui/never_patterns/check.rs create mode 100644 tests/ui/never_patterns/check.stderr create mode 100644 tests/ui/parser/match-arm-without-body.rs create mode 100644 tests/ui/parser/match-arm-without-body.stderr 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:: { + Some(!) => {} + None => {} + } + match None:: { + Some(!) if true, + //~^ ERROR expected one of + None => {} + } + match None:: { + Some(!) if true => {} + None => {} + } + match None:: { + 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 {