diff options
| author | Nick Cameron <nrc@ncameron.org> | 2018-02-19 18:37:59 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-19 18:37:59 +1300 |
| commit | 377bb5c97f87bba2d4324372f2e4ddf82ee2ff53 (patch) | |
| tree | f94ec10a4481ed9f9314facd881c1d132a17625c | |
| parent | 383e7e9955fdd988548e316008604c173fd7b369 (diff) | |
| parent | 37f82a0c9545dcfed01ee87f906b221fe7f2c5f6 (diff) | |
Merge pull request #2467 from topecongiro/issue-2466
Skip formatting macro_rules! that are not using {} | -rw-r--r-- | rustfmt-core/src/macros.rs | 3 | ||||
| -rw-r--r-- | rustfmt-core/tests/source/macro_rules.rs | 9 | ||||
| -rw-r--r-- | rustfmt-core/tests/target/macro_rules.rs | 9 |
3 files changed, 21 insertions, 0 deletions
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<String> { 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 [ + () => () +]; |
