]> git.lizzy.rs Git - rust.git/commitdiff
Skip formatting macro_rules! that are not using {}
authortopecongiro <seuchida@gmail.com>
Mon, 19 Feb 2018 05:08:33 +0000 (14:08 +0900)
committertopecongiro <seuchida@gmail.com>
Mon, 19 Feb 2018 05:08:33 +0000 (14:08 +0900)
rustfmt-core/src/macros.rs
rustfmt-core/tests/source/macro_rules.rs
rustfmt-core/tests/target/macro_rules.rs

index a8a8c28c585b28f3b28fbce04a2b939a053f3c6c..0633c223c5fde50f423705004ff3abb1874dda73 100644 (file)
@@ -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() {
index 02c9717e11e047ce8c638c0456d076866911a4fd..4900574c4eb9bd1796e95765ca24d3957bf92b52 100644 (file)
@@ -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 [
+    () => ()
+];
index b2f4fc067ac7e17be1617806d37fe7753a2e7821..e6f779d8a03c3827d26f2b3fd203168546ddb7af 100644 (file)
@@ -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 [
+    () => ()
+];