From 37f82a0c9545dcfed01ee87f906b221fe7f2c5f6 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Mon, 19 Feb 2018 14:08:33 +0900 Subject: [PATCH] Skip formatting macro_rules! that are not using {} --- rustfmt-core/src/macros.rs | 3 +++ rustfmt-core/tests/source/macro_rules.rs | 9 +++++++++ rustfmt-core/tests/target/macro_rules.rs | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/rustfmt-core/src/macros.rs b/rustfmt-core/src/macros.rs index a8a8c28c585..0633c223c5f 100644 --- a/rustfmt-core/src/macros.rs +++ b/rustfmt-core/src/macros.rs @@ -294,6 +294,9 @@ pub fn rewrite_macro_def( span: Span, ) -> Option { let snippet = Some(remove_trailing_white_spaces(context.snippet(span))); + if snippet.as_ref().map_or(true, |s| s.ends_with(";")) { + return snippet; + } let mut parser = MacroParser::new(def.stream().into_trees()); let parsed_def = match parser.parse() { diff --git a/rustfmt-core/tests/source/macro_rules.rs b/rustfmt-core/tests/source/macro_rules.rs index 02c9717e11e..4900574c4eb 100644 --- a/rustfmt-core/tests/source/macro_rules.rs +++ b/rustfmt-core/tests/source/macro_rules.rs @@ -68,3 +68,12 @@ macro_rules! m { $line3_xxxxxxxxxxxxxxxxx: expr, ) => {}; } + +// #2466 +// Skip formatting `macro_rules!` that are not using `{}`. +macro_rules! m ( + () => () +); +macro_rules! m [ + () => () +]; diff --git a/rustfmt-core/tests/target/macro_rules.rs b/rustfmt-core/tests/target/macro_rules.rs index b2f4fc067ac..e6f779d8a03 100644 --- a/rustfmt-core/tests/target/macro_rules.rs +++ b/rustfmt-core/tests/target/macro_rules.rs @@ -59,3 +59,12 @@ macro_rules! m { $line3_xxxxxxxxxxxxxxxxx: expr, ) => {}; } + +// #2466 +// Skip formatting `macro_rules!` that are not using `{}`. +macro_rules! m ( + () => () +); +macro_rules! m [ + () => () +]; -- 2.44.0