Skip to content

Commit 5ff7b63

Browse files
dtolnaycalebcartwright
authored andcommitted
Preserve semicolon after macro call inside foreign mod
1 parent 8e94761 commit 5ff7b63

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/macros.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ fn rewrite_macro_name(
112112
fn return_macro_parse_failure_fallback(
113113
context: &RewriteContext<'_>,
114114
indent: Indent,
115+
position: MacroPosition,
115116
span: Span,
116117
) -> Option<String> {
117118
// Mark this as a failure however we format it
@@ -140,7 +141,11 @@ fn return_macro_parse_failure_fallback(
140141
));
141142

142143
// Return the snippet unmodified if the macro is not block-like
143-
Some(context.snippet(span).to_owned())
144+
let mut snippet = context.snippet(span).to_owned();
145+
if position == MacroPosition::Item {
146+
snippet.push(';');
147+
}
148+
Some(snippet)
144149
}
145150

146151
pub(crate) fn rewrite_macro(
@@ -233,7 +238,12 @@ fn rewrite_macro_inner(
233238
} = match parse_macro_args(context, ts, style, is_forced_bracket) {
234239
Some(args) => args,
235240
None => {
236-
return return_macro_parse_failure_fallback(context, shape.indent, mac.span());
241+
return return_macro_parse_failure_fallback(
242+
context,
243+
shape.indent,
244+
position,
245+
mac.span(),
246+
);
237247
}
238248
};
239249

tests/source/extern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ macro_rules! x {
8484

8585
extern "macros" {
8686
x!(ident);
87-
// x!(#); FIXME
87+
x!(#);
8888
x![ident];
89-
// x![#]; FIXME
89+
x![#];
9090
x! {ident}
9191
x! {#}
9292
}

tests/target/extern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ macro_rules! x {
8989

9090
extern "macros" {
9191
x!(ident);
92-
// x!(#); FIXME
92+
x!(#);
9393
x![ident];
94-
// x![#]; FIXME
94+
x![#];
9595
x! {ident}
9696
x! {#}
9797
}

0 commit comments

Comments
 (0)