summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfcs/rfc-0000-never_patterns
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /tests/ui/rfcs/rfc-0000-never_patterns
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/rfcs/rfc-0000-never_patterns')
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/check.rs33
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/check.stderr35
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/parse.rs71
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/parse.stderr44
4 files changed, 183 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs
new file mode 100644
index 000000000..e29811224
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs
@@ -0,0 +1,33 @@
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+enum Void {}
+
+fn main() {}
+
+macro_rules! never {
+ () => { ! }
+}
+
+fn no_arms_or_guards(x: Void) {
+ match None::<Void> {
+ Some(!) => {}
+ //~^ ERROR a never pattern is always unreachable
+ None => {}
+ }
+ match None::<Void> {
+ Some(!) if true,
+ //~^ ERROR guard on a never pattern
+ None => {}
+ }
+ match None::<Void> {
+ Some(!) if true => {}
+ //~^ ERROR a never pattern is always unreachable
+ None => {}
+ }
+ match None::<Void> {
+ Some(never!()) => {},
+ //~^ ERROR a never pattern is always unreachable
+ None => {}
+ }
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr
new file mode 100644
index 000000000..bfbc7a1b5
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr
@@ -0,0 +1,35 @@
+error: a never pattern is always unreachable
+ --> $DIR/check.rs:14:20
+ |
+LL | Some(!) => {}
+ | ^^
+ | |
+ | this will never be executed
+ | help: remove this expression
+
+error: a guard on a never pattern will never be run
+ --> $DIR/check.rs:19:20
+ |
+LL | Some(!) if true,
+ | ^^^^ help: remove this guard
+
+error: a never pattern is always unreachable
+ --> $DIR/check.rs:24:28
+ |
+LL | Some(!) if true => {}
+ | ^^
+ | |
+ | this will never be executed
+ | help: remove this expression
+
+error: a never pattern is always unreachable
+ --> $DIR/check.rs:29:27
+ |
+LL | Some(never!()) => {},
+ | ^^
+ | |
+ | this will never be executed
+ | help: remove this expression
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/parse.rs b/tests/ui/rfcs/rfc-0000-never_patterns/parse.rs
new file mode 100644
index 000000000..1b23e60e0
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/parse.rs
@@ -0,0 +1,71 @@
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+enum Void {}
+
+fn main() {}
+
+macro_rules! never {
+ () => { ! }
+}
+
+fn parse(x: Void) {
+ match None::<Void> {
+ None => {}
+ Some(!),
+ }
+ match None::<Void> {
+ Some(!),
+ None => {}
+ }
+ match None::<Void> {
+ None => {}
+ Some(!)
+ }
+ match None::<Void> {
+ Some(!)
+ //~^ ERROR expected `,` following `match` arm
+ None => {}
+ }
+ match None::<Void> {
+ Some(!) if true
+ //~^ ERROR expected `,` following `match` arm
+ //~| ERROR guard on a never pattern
+ None => {}
+ }
+ match None::<Void> {
+ Some(!) if true,
+ //~^ ERROR guard on a never pattern
+ None => {}
+ }
+ match None::<Void> {
+ Some(!) <=
+ //~^ ERROR expected one of
+ }
+ match x {
+ never!(),
+ }
+ match x {
+ never!() if true,
+ //~^ ERROR guard on a never pattern
+ }
+ match x {
+ never!()
+ }
+ match &x {
+ &never!(),
+ }
+ match None::<Void> {
+ Some(never!()),
+ None => {}
+ }
+ match x { ! }
+ match &x { &! }
+
+ let res: Result<bool, Void> = Ok(false);
+ let Ok(_) = res;
+ let Ok(_) | Err(!) = &res; // Disallowed; see #82048.
+ //~^ ERROR top-level or-patterns are not allowed in `let` bindings
+ let (Ok(_) | Err(!)) = &res;
+ let (Ok(_) | Err(&!)) = res.as_ref();
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/parse.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/parse.stderr
new file mode 100644
index 000000000..e81a13a39
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/parse.stderr
@@ -0,0 +1,44 @@
+error: expected `,` following `match` arm
+ --> $DIR/parse.rs:26:16
+ |
+LL | Some(!)
+ | ^ help: missing a comma here to end this `match` arm: `,`
+
+error: expected `,` following `match` arm
+ --> $DIR/parse.rs:31:24
+ |
+LL | Some(!) if true
+ | ^ help: missing a comma here to end this `match` arm: `,`
+
+error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `<=`
+ --> $DIR/parse.rs:42:17
+ |
+LL | Some(!) <=
+ | ^^ expected one of `,`, `=>`, `if`, `|`, or `}`
+
+error: top-level or-patterns are not allowed in `let` bindings
+ --> $DIR/parse.rs:67:9
+ |
+LL | let Ok(_) | Err(!) = &res; // Disallowed; see #82048.
+ | ^^^^^^^^^^^^^^ help: wrap the pattern in parentheses: `(Ok(_) | Err(!))`
+
+error: a guard on a never pattern will never be run
+ --> $DIR/parse.rs:31:20
+ |
+LL | Some(!) if true
+ | ^^^^ help: remove this guard
+
+error: a guard on a never pattern will never be run
+ --> $DIR/parse.rs:37:20
+ |
+LL | Some(!) if true,
+ | ^^^^ help: remove this guard
+
+error: a guard on a never pattern will never be run
+ --> $DIR/parse.rs:49:21
+ |
+LL | never!() if true,
+ | ^^^^ help: remove this guard
+
+error: aborting due to 7 previous errors
+