diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-06-21 07:37:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-21 07:37:02 +0200 |
| commit | c6710d15f1228a5a3fda4c1aa307c3073ed83c9e (patch) | |
| tree | 3bfcdc2ff050b834f4c58dde27d4b902dfa63afc /compiler/rustc_parse/src/parser | |
| parent | a98c14f3a9326e00d4c0734138308bf98206baa6 (diff) | |
| parent | b967f5c30d69fd44933ace40598eae6dfdeaa6a4 (diff) | |
| download | rust-c6710d15f1228a5a3fda4c1aa307c3073ed83c9e.tar.gz rust-c6710d15f1228a5a3fda4c1aa307c3073ed83c9e.zip | |
Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Syntactically accept `become` expressions (explicit tail calls experiment) This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature. cc `@scottmcm`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f00bc54589a..88c6cc1ae70 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1430,6 +1430,8 @@ impl<'a> Parser<'a> { self.parse_expr_yield() } else if self.is_do_yeet() { self.parse_expr_yeet() + } else if self.eat_keyword(kw::Become) { + self.parse_expr_become() } else if self.check_keyword(kw::Let) { self.parse_expr_let() } else if self.eat_keyword(kw::Underscore) { @@ -1746,6 +1748,16 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr) } + /// Parse `"become" expr`, with `"become"` token already eaten. + fn parse_expr_become(&mut self) -> PResult<'a, P<Expr>> { + let lo = self.prev_token.span; + let kind = ExprKind::Become(self.parse_expr()?); + let span = lo.to(self.prev_token.span); + self.sess.gated_spans.gate(sym::explicit_tail_calls, span); + let expr = self.mk_expr(span, kind); + self.maybe_recover_from_bad_qpath(expr) + } + /// Parse `"break" (('label (:? expr)?) | expr?)` with `"break"` token already eaten. /// If the label is followed immediately by a `:` token, the label and `:` are /// parsed as part of the expression (i.e. a labeled loop). The language team has |
