Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests
  • Loading branch information
Nadrieril committed Dec 2, 2023
commit caa488b96e65131e4d70f219d5e89008031f9229
30 changes: 30 additions & 0 deletions tests/ui/never_patterns/check.rs
Original file line number Diff line number Diff line change
@@ -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 => {}
}
}
8 changes: 8 additions & 0 deletions tests/ui/never_patterns/check.stderr
Original file line number Diff line number Diff line change
@@ -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

68 changes: 68 additions & 0 deletions tests/ui/parser/match-arm-without-body.rs
Original file line number Diff line number Diff line change
@@ -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
_ => {}
}
}
122 changes: 122 additions & 0 deletions tests/ui/parser/match-arm-without-body.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/ui/pattern/never_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down