-
Notifications
You must be signed in to change notification settings - Fork 13.4k
try_block cannot be used everywhere an expression can #56828
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
cc @scottmcm |
I believe the error is expected here, the same as with the following struct literal match in 2015: struct try { x: i32 }
fn main() {
let x = 1;
match try { x } {
try { .. } => {}
}
} Which also needs to be That said, the warning to remove the necessary parens is definitely wrong. EDIT: Hmm, I might be wrong, actually. The following compiles, which surprised me: for _ in if true { [1].iter() } else { [0].iter() } { } as does this: match loop { break } { So maybe the parser restriction is only for struct literals, not for keyword-introduced expressions. |
Yeah I think |
This is exactly what a thought. I didn't know that this:
was not allowed, so in my head the parentheses were always redundant. Is there any reason for why we need parentheses around a struct literal? A parser ambiguity, maybe? Because I would expect that to work, too. |
for x in (Thing { x })
{
println!("This is the loop body.");
}
for x in Thing { x }
{
println!("This is a block expression.");
} For match (Thing {})
{} // Parsed as the match block. ERROR: Missing `_` branch
let thing: ! = panic!();
match thing {}
{} // Parsed as a block expression statement |
Allow `try`-blocks in places where an open delim is expected Closes rust-lang#70490 Closes rust-lang#56828 r? @Centril
The following code fails to compile (
rustc --edition=2018
):The compiler error is:
Adding parentheses or braces, it will compile fine:
The same issue happens with other constructs such as:
The text was updated successfully, but these errors were encountered: