Skip to content

Commit

Permalink
Parse explicit tail calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 22, 2024
1 parent 4132a0c commit 07f4b37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,8 @@ pub(crate) mod parsing {
input.parse().map(Expr::Continue)
} else if input.peek(Token![return]) {
input.parse().map(Expr::Return)
} else if input.peek(Token![become]) {
expr_become(input)
} else if input.peek(token::Bracket) {
array_or_repeat(input)
} else if input.peek(Token![let]) {
Expand Down Expand Up @@ -2393,6 +2395,16 @@ pub(crate) mod parsing {
}
}

#[cfg(feature = "full")]
fn expr_become(input: ParseStream) -> Result<Expr> {
let begin = input.fork();
input.parse::<Token![become]>()?;
if can_begin_expr(input) {
input.parse::<Expr>()?;
}
Ok(Expr::Verbatim(verbatim::between(&begin, input)))
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for ExprTryBlock {
Expand Down
13 changes: 0 additions & 13 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ static EXCLUDE_FILES: &[&str] = &[
"tests/ui/attributes/unsafe/unsafe-attributes.rs",
"tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs",

// TODO: explicit tail calls: `become _g()`
// https://github.com/dtolnay/syn/issues/1501
"src/tools/miri/tests/fail/tail_calls/cc-mismatch.rs",
"src/tools/miri/tests/fail/tail_calls/signature-mismatch-arg.rs",
"src/tools/miri/tests/pass/tail_call.rs",
"src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0209_become_expr.rs",
"tests/mir-opt/tail_call_drops.rs",
"tests/ui/explicit-tail-calls/ctfe-arg-good-borrow.rs",
"tests/ui/explicit-tail-calls/ctfe-arg-move.rs",
"tests/ui/explicit-tail-calls/ctfe-collatz-multi-rec.rs",
"tests/ui/explicit-tail-calls/drop-order.rs",
"tests/ui/explicit-tail-calls/return-lifetime-sub.rs",

// TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
// https://github.com/dtolnay/syn/issues/1435
"src/tools/rustfmt/tests/source/issue_5721.rs",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn librustc_parenthesize(mut librustc_expr: P<ast::Expr>) -> P<ast::Expr> {

fn noop_visit_expr<T: MutVisitor>(e: &mut Expr, vis: &mut T) {
match &mut e.kind {
ExprKind::AddrOf(BorrowKind::Raw, ..) => {}
ExprKind::AddrOf(BorrowKind::Raw, ..) | ExprKind::Become(..) => {}
ExprKind::Struct(expr) => {
let StructExpr {
qself,
Expand Down

0 comments on commit 07f4b37

Please sign in to comment.