review comment: move recovery code to its own function
This commit is contained in:
parent
b82ec362ca
commit
ffc623ab93
1 changed files with 19 additions and 2 deletions
|
@ -1049,6 +1049,23 @@ impl<'a> Parser<'a> {
|
||||||
let mut seq = self.parse_paren_expr_seq().map(|args| {
|
let mut seq = self.parse_paren_expr_seq().map(|args| {
|
||||||
self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args), AttrVec::new())
|
self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args), AttrVec::new())
|
||||||
});
|
});
|
||||||
|
if let Some(expr) =
|
||||||
|
self.maybe_recover_struct_lit_bad_delims(lo, open_paren, &mut seq, snapshot)
|
||||||
|
{
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
self.recover_seq_parse_error(token::Paren, lo, seq)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If we encounter a parser state that looks like the user has written a `struct` literal with
|
||||||
|
/// parentheses instead of braces, recover the parser state and provide suggestions.
|
||||||
|
fn maybe_recover_struct_lit_bad_delims(
|
||||||
|
&mut self,
|
||||||
|
lo: Span,
|
||||||
|
open_paren: Span,
|
||||||
|
seq: &mut PResult<'a, P<Expr>>,
|
||||||
|
snapshot: Option<(Self, ExprKind)>,
|
||||||
|
) -> Option<P<Expr>> {
|
||||||
match (seq.as_mut(), snapshot) {
|
match (seq.as_mut(), snapshot) {
|
||||||
(Err(ref mut err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
(Err(ref mut err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
||||||
let name = pprust::path_to_string(&path);
|
let name = pprust::path_to_string(&path);
|
||||||
|
@ -1079,7 +1096,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
return self.mk_expr_err(span);
|
return Some(self.mk_expr_err(span));
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(mut err) => err.emit(),
|
Err(mut err) => err.emit(),
|
||||||
|
@ -1087,7 +1104,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.recover_seq_parse_error(token::Paren, lo, seq)
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an indexing expression `expr[...]`.
|
/// Parse an indexing expression `expr[...]`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue