From 342ea154906163a678c257469823d7c7383014d6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 5 Jan 2024 10:08:47 +0100 Subject: [PATCH] Add tests --- tests/ui/pattern/never_patterns.rs | 23 ---------- tests/ui/pattern/never_patterns.stderr | 34 +-------------- .../rfcs/rfc-0000-never_patterns/bindings.rs | 28 ++++++++++++ .../rfc-0000-never_patterns/bindings.stderr | 43 +++++++++++++++++++ 4 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/bindings.rs create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/bindings.stderr diff --git a/tests/ui/pattern/never_patterns.rs b/tests/ui/pattern/never_patterns.rs index 915f3e75e7b..eb2421204ae 100644 --- a/tests/ui/pattern/never_patterns.rs +++ b/tests/ui/pattern/never_patterns.rs @@ -74,26 +74,3 @@ fn never_pattern_location(void: Void) { Some(&(_, !)), } } - -fn never_and_bindings() { - let x: Result = Ok(false); - - // FIXME(never_patterns): Never patterns in or-patterns don't need to share the same bindings. - match x { - Ok(_x) | Err(&!) => {} - //~^ ERROR: is not bound in all patterns - } - let (Ok(_x) | Err(&!)) = x; - //~^ ERROR: is not bound in all patterns - - // FIXME(never_patterns): A never pattern mustn't have bindings. - match x { - Ok(_) => {} - Err(&(_b, !)), - } - match x { - Ok(_a) | Err(&(_b, !)) => {} - //~^ ERROR: is not bound in all patterns - //~| ERROR: is not bound in all patterns - } -} diff --git a/tests/ui/pattern/never_patterns.stderr b/tests/ui/pattern/never_patterns.stderr index 11e50debfd3..f3787f9816a 100644 --- a/tests/ui/pattern/never_patterns.stderr +++ b/tests/ui/pattern/never_patterns.stderr @@ -14,38 +14,6 @@ LL | let (Ok(_x) | Err(&!)) = res.as_ref(); | | | variable not in all patterns -error[E0408]: variable `_x` is not bound in all patterns - --> $DIR/never_patterns.rs:83:18 - | -LL | Ok(_x) | Err(&!) => {} - | -- ^^^^^^^ pattern doesn't bind `_x` - | | - | variable not in all patterns - -error[E0408]: variable `_x` is not bound in all patterns - --> $DIR/never_patterns.rs:86:19 - | -LL | let (Ok(_x) | Err(&!)) = x; - | -- ^^^^^^^ pattern doesn't bind `_x` - | | - | variable not in all patterns - -error[E0408]: variable `_b` is not bound in all patterns - --> $DIR/never_patterns.rs:95:9 - | -LL | Ok(_a) | Err(&(_b, !)) => {} - | ^^^^^^ -- variable not in all patterns - | | - | pattern doesn't bind `_b` - -error[E0408]: variable `_a` is not bound in all patterns - --> $DIR/never_patterns.rs:95:18 - | -LL | Ok(_a) | Err(&(_b, !)) => {} - | -- ^^^^^^^^^^^^^ pattern doesn't bind `_a` - | | - | variable not in all patterns - -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0408`. diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/bindings.rs b/tests/ui/rfcs/rfc-0000-never_patterns/bindings.rs new file mode 100644 index 00000000000..61a4231e5da --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/bindings.rs @@ -0,0 +1,28 @@ +#![feature(never_patterns)] +#![allow(incomplete_features)] + +enum Void {} + +fn main() { + let x: Result = Ok(false); + + // FIXME(never_patterns): Never patterns in or-patterns don't need to share the same bindings. + match x { + Ok(_x) | Err(&!) => {} + //~^ ERROR: is not bound in all patterns + } + let (Ok(_x) | Err(&!)) = x; + //~^ ERROR: is not bound in all patterns + + // FIXME(never_patterns): A never pattern mustn't have bindings. + match x { + Ok(_) => {} + Err(&(_a, _b, !)), + } + match x { + Ok(_ok) | Err(&(_a, _b, !)) => {} + //~^ ERROR: is not bound in all patterns + //~| ERROR: is not bound in all patterns + //~| ERROR: is not bound in all patterns + } +} diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/bindings.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/bindings.stderr new file mode 100644 index 00000000000..56cefcb51f3 --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/bindings.stderr @@ -0,0 +1,43 @@ +error[E0408]: variable `_x` is not bound in all patterns + --> $DIR/bindings.rs:11:18 + | +LL | Ok(_x) | Err(&!) => {} + | -- ^^^^^^^ pattern doesn't bind `_x` + | | + | variable not in all patterns + +error[E0408]: variable `_x` is not bound in all patterns + --> $DIR/bindings.rs:14:19 + | +LL | let (Ok(_x) | Err(&!)) = x; + | -- ^^^^^^^ pattern doesn't bind `_x` + | | + | variable not in all patterns + +error[E0408]: variable `_a` is not bound in all patterns + --> $DIR/bindings.rs:23:9 + | +LL | Ok(_ok) | Err(&(_a, _b, !)) => {} + | ^^^^^^^ -- variable not in all patterns + | | + | pattern doesn't bind `_a` + +error[E0408]: variable `_b` is not bound in all patterns + --> $DIR/bindings.rs:23:9 + | +LL | Ok(_ok) | Err(&(_a, _b, !)) => {} + | ^^^^^^^ -- variable not in all patterns + | | + | pattern doesn't bind `_b` + +error[E0408]: variable `_ok` is not bound in all patterns + --> $DIR/bindings.rs:23:19 + | +LL | Ok(_ok) | Err(&(_a, _b, !)) => {} + | --- ^^^^^^^^^^^^^^^^^ pattern doesn't bind `_ok` + | | + | variable not in all patterns + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0408`.