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:
commit
8f111951a1
3 changed files with 29 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue