Closed
Description
The following code fails to compile (rustc --edition=2018
):
#![feature(try_blocks)]
fn main() {
match try { 0 } {
None => (),
Some(_) => ()
};
}
The compiler error is:
error: expected expression, found reserved keyword `try`
--> test.rs:3:11
|
3 | match try { 0 } {
| ----- ^^^ expected expression
| |
| while parsing this match expression
Adding parentheses or braces, it will compile fine:
match ( try { 0 } ) { ... } //warning: unnecessary parentheses around `match` head expression
match { try { 0 } } { ... }
The same issue happens with other constructs such as:
if let Some(_) = try { 0 } { }
for _ in try { 0 } { } //should fail because of "cannot infer type", not "expected expression"