From d2881c32e67ada6f4273b0ad232af0389ddc16b7 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 24 Aug 2024 00:00:49 -0700 Subject: [PATCH] Pretty-print tail calls (`become`) --- Cargo.toml | 4 ++-- src/expr.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d951596..56dd9bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,13 +19,13 @@ verbatim = ["syn/parsing"] [dependencies] proc-macro2 = { version = "1.0.80", default-features = false } -syn = { version = "2.0.59", default-features = false, features = ["full"] } +syn = { version = "2.0.76", default-features = false, features = ["full"] } [dev-dependencies] indoc = "2" proc-macro2 = { version = "1.0.80", default-features = false } quote = { version = "1.0.35", default-features = false } -syn = { version = "2.0.59", default-features = false, features = ["parsing"] } +syn = { version = "2.0.76", default-features = false, features = ["parsing"] } [lib] doc-scrape-examples = false diff --git a/src/expr.rs b/src/expr.rs index 4927c86..1521a29 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -681,10 +681,16 @@ impl Printer { enum ExprVerbatim { Empty, Ellipsis, + Become(Become), Builtin(Builtin), RawReference(RawReference), } + struct Become { + attrs: Vec, + tail_call: Expr, + } + struct Builtin { attrs: Vec, name: Ident, @@ -709,6 +715,11 @@ impl Printer { let lookahead = ahead.lookahead1(); if input.is_empty() { Ok(ExprVerbatim::Empty) + } else if lookahead.peek(Token![become]) { + input.advance_to(&ahead); + input.parse::()?; + let tail_call: Expr = input.parse()?; + Ok(ExprVerbatim::Become(Become { attrs, tail_call })) } else if lookahead.peek(kw::builtin) { input.advance_to(&ahead); input.parse::()?; @@ -751,6 +762,12 @@ impl Printer { ExprVerbatim::Ellipsis => { self.word("..."); } + ExprVerbatim::Become(expr) => { + self.outer_attrs(&expr.attrs); + self.word("become"); + self.nbsp(); + self.expr(&expr.tail_call); + } ExprVerbatim::Builtin(expr) => { self.outer_attrs(&expr.attrs); self.word("builtin # ");