Closed
Description
Currently do catch
can't appear before blocks.
#![feature(catch_expr)]
fn main() {
if let Ok(x) = do catch { Err("foo") as Result<i32, _> } {
println!("x = {}", x);
}
}
rustc 1.19.0-nightly (76242aebb 2017-06-06)
error: expected expression, found reserved keyword `do`
--> <anon>:3:20
|
3 | if let Ok(x) = do catch { Err("foo") as Result<i32, _> } {
| ^^
error: aborting due to previous error(s)
One has to enclose the do catch
with parentheses.
#![feature(catch_expr)]
fn main() {
if let Ok(x) = (do catch { Err("foo") as Result<i32, _> }) {
println!("x = {}", x);
}
}
rustc 1.19.0-nightly (76242aebb 2017-06-06)
warning: unnecessary parentheses around `if let` head expression
--> <anon>:3:20
|
3 | if let Ok(x) = (do catch { Err("foo") as Result<i32, _> }) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_parens)] on by default
I think it is inconsistent with the behavior like this:
fn main() {
// compiles.
if if true { true } else { false } {
}
}
The RESTRICTION_NO_STRUCT_LITERAL
is mainly used to distinguish if x == (A { .. }) { .. }
from if x == A { .. }
and unnecessary for do catch {}
where {}
definitely comes here.
At least the emitted warning for (do catch { .. })
is wrong and the emitted error for do catch { .. }
is unhelpful for now.