From 5ff7b632a95bac6955611d85040859128902c580 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 29 Mar 2022 12:59:07 -0700 Subject: [PATCH] Preserve semicolon after macro call inside foreign mod --- src/macros.rs | 14 ++++++++++++-- tests/source/extern.rs | 4 ++-- tests/target/extern.rs | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index fdbe3374615..664f152e8be 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -112,6 +112,7 @@ fn rewrite_macro_name( fn return_macro_parse_failure_fallback( context: &RewriteContext<'_>, indent: Indent, + position: MacroPosition, span: Span, ) -> Option { // Mark this as a failure however we format it @@ -140,7 +141,11 @@ fn return_macro_parse_failure_fallback( )); // Return the snippet unmodified if the macro is not block-like - Some(context.snippet(span).to_owned()) + let mut snippet = context.snippet(span).to_owned(); + if position == MacroPosition::Item { + snippet.push(';'); + } + Some(snippet) } pub(crate) fn rewrite_macro( @@ -233,7 +238,12 @@ fn rewrite_macro_inner( } = match parse_macro_args(context, ts, style, is_forced_bracket) { Some(args) => args, None => { - return return_macro_parse_failure_fallback(context, shape.indent, mac.span()); + return return_macro_parse_failure_fallback( + context, + shape.indent, + position, + mac.span(), + ); } }; diff --git a/tests/source/extern.rs b/tests/source/extern.rs index 5b981385d2b..f51ba6e98c9 100644 --- a/tests/source/extern.rs +++ b/tests/source/extern.rs @@ -84,9 +84,9 @@ macro_rules! x { extern "macros" { x!(ident); - // x!(#); FIXME + x!(#); x![ident]; - // x![#]; FIXME + x![#]; x! {ident} x! {#} } diff --git a/tests/target/extern.rs b/tests/target/extern.rs index 570d21c17df..d1741360cfd 100644 --- a/tests/target/extern.rs +++ b/tests/target/extern.rs @@ -89,9 +89,9 @@ macro_rules! x { extern "macros" { x!(ident); - // x!(#); FIXME + x!(#); x![ident]; - // x![#]; FIXME + x![#]; x! {ident} x! {#} }