Rollup merge of #59847 - Kampfkarren:try-block-catch, r=estebank

Error when using `catch` after `try`

Part of https://github.com/rust-lang/rust/issues/31436
This commit is contained in:
Mazdak Farrokhzad
2019-04-12 20:36:11 +02:00
committed by GitHub
3 changed files with 29 additions and 1 deletions

View File

@@ -4091,7 +4091,15 @@ impl<'a> Parser<'a> {
{
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
if self.eat_keyword(keywords::Catch) {
let mut error = self.struct_span_err(self.prev_span,
"keyword `catch` cannot follow a `try` block");
error.help("try using `match` on the result of the `try` block instead");
error.emit();
Err(error)
} else {
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
}
}
// `match` token already eaten