1
Fork 0

Silence unnecessary await foo? knock-down error

This commit is contained in:
Esteban Küber 2020-10-22 10:51:49 -07:00
parent 62ba365195
commit 3a0227bc49
3 changed files with 40 additions and 68 deletions

View file

@ -1207,7 +1207,13 @@ impl<'a> Parser<'a> {
self.recover_await_prefix(await_sp)?
};
let sp = self.error_on_incorrect_await(lo, hi, &expr, is_question);
let expr = self.mk_expr(lo.to(sp), ExprKind::Await(expr), attrs);
let kind = match expr.kind {
// Avoid knock-down errors as we don't know whether to interpret this as `foo().await?`
// or `foo()?.await` (the very reason we went with postfix syntax 😅).
ExprKind::Try(_) => ExprKind::Err,
_ => ExprKind::Await(expr),
};
let expr = self.mk_expr(lo.to(sp), kind, attrs);
self.maybe_recover_from_bad_qpath(expr, true)
}