Refactor YieldKind so postfix yield must have an expression

This commit is contained in:
Eric Holk 2025-03-18 12:19:43 -07:00
parent 299e5d0514
commit 2bd7f73c21
No known key found for this signature in database
GPG key ID: F1A772BB658A63E1
14 changed files with 65 additions and 30 deletions

View file

@ -1315,8 +1315,9 @@ impl<'a> Parser<'a> {
if self.eat_keyword(exp!(Yield)) {
let yield_span = self.prev_token.span;
self.psess.gated_spans.gate(sym::yield_expr, yield_span);
return Ok(self
.mk_expr(lo.to(yield_span), ExprKind::Yield(Some(self_arg), YieldKind::Postfix)));
return Ok(
self.mk_expr(lo.to(yield_span), ExprKind::Yield(YieldKind::Postfix(self_arg)))
);
}
let fn_span_lo = self.token.span;
@ -1893,7 +1894,7 @@ impl<'a> Parser<'a> {
/// Parse `"yield" expr?`.
fn parse_expr_yield(&mut self) -> PResult<'a, P<Expr>> {
let lo = self.prev_token.span;
let kind = ExprKind::Yield(self.parse_expr_opt()?, YieldKind::Prefix);
let kind = ExprKind::Yield(YieldKind::Prefix(self.parse_expr_opt()?));
let span = lo.to(self.prev_token.span);
self.psess.gated_spans.gate(sym::yield_expr, span);
let expr = self.mk_expr(span, kind);
@ -4047,7 +4048,7 @@ impl MutVisitor for CondChecker<'_> {
| ExprKind::MacCall(_)
| ExprKind::Struct(_)
| ExprKind::Repeat(_, _)
| ExprKind::Yield(_, _)
| ExprKind::Yield(_)
| ExprKind::Yeet(_)
| ExprKind::Become(_)
| ExprKind::IncludedBytes(_)