From ef42361c6c90dcaf0043b57e07743c6f4da59a02 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 31 May 2026 20:35:03 +0100 Subject: [PATCH 1/4] Allow rustfmt to pretty-print inside goto_block Make the statements inside goto_block printable, i.e. change form label => {} to label: {} --- libcc2rs-macros/src/goto.rs | 30 +++- libcc2rs-macros/src/lib.rs | 6 +- libcc2rs-macros/tests/control_flow.rs | 206 ++++++++++++++++++++++++-- 3 files changed, 216 insertions(+), 26 deletions(-) diff --git a/libcc2rs-macros/src/goto.rs b/libcc2rs-macros/src/goto.rs index cb8ece18..7a19808e 100644 --- a/libcc2rs-macros/src/goto.rs +++ b/libcc2rs-macros/src/goto.rs @@ -33,15 +33,29 @@ struct GotoArm { impl Parse for GotoBlockInput { fn parse(input: ParseStream) -> syn::Result { + let block: Block = input.parse()?; let mut arms = Vec::new(); - while !input.is_empty() { - let label: Lifetime = input.parse()?; - input.parse::]>()?; - let body: Expr = input.parse()?; - arms.push(GotoArm { label, body }); - if input.peek(Token![,]) { - input.parse::()?; - } + for stmt in block.stmts { + let Stmt::Expr(Expr::Block(eb), _) = stmt else { + return Err(syn::Error::new( + Span::call_site(), + "goto_block! body must be a sequence of labeled blocks", + )); + }; + let Some(label) = eb.label else { + return Err(syn::Error::new( + Span::call_site(), + "goto_block! arm must be a labeled block", + )); + }; + arms.push(GotoArm { + label: label.name, + body: Expr::Block(ExprBlock { + attrs: eb.attrs, + label: None, + block: eb.block, + }), + }); } Ok(Self { arms }) } diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 10317cf4..31310aff 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -36,10 +36,10 @@ pub fn switch(input: TokenStream) -> TokenStream { switch::expand(input) } -// goto_block! { -// '