]> git.lizzy.rs Git - rust.git/blobdiff - src/macros.rs
Fixup formatting
[rust.git] / src / macros.rs
index 7348e7a0315cdcfe0b645a4df43791a8a8cafb56..49f4a03ee1db8a7afecdf7f05e8eb8186b6817df 100644 (file)
@@ -64,6 +64,15 @@ pub enum MacroArg {
     Item(ptr::P<ast::Item>),
 }
 
+impl MacroArg {
+    fn is_item(&self) -> bool {
+        match self {
+            MacroArg::Item(..) => true,
+            _ => false,
+        }
+    }
+}
+
 impl Rewrite for ast::Item {
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         let mut visitor = ::visitor::FmtVisitor::from_context(context);
@@ -260,6 +269,7 @@ pub fn rewrite_macro_inner(
                     }
                     return return_original_snippet_with_failure_marked(context, mac.span);
                 }
+                _ if arg_vec.last().map_or(false, MacroArg::is_item) => continue,
                 _ => return return_original_snippet_with_failure_marked(context, mac.span),
             }
 
@@ -272,13 +282,7 @@ pub fn rewrite_macro_inner(
         }
     }
 
-    if !arg_vec.is_empty() && arg_vec.iter().all(|arg| {
-        if let MacroArg::Item(..) = arg {
-            true
-        } else {
-            false
-        }
-    }) {
+    if !arg_vec.is_empty() && arg_vec.iter().all(MacroArg::is_item) {
         return rewrite_macro_with_items(
             context,
             &arg_vec,
@@ -1164,22 +1168,24 @@ fn indent_macro_snippet(
         .min()?;
 
     Some(
-        first_line + "\n" + &trimmed_lines
-            .iter()
-            .map(
-                |&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
-                    _ if !trimmed => line.to_owned(),
-                    Some(original_indent_width) => {
-                        let new_indent_width = indent.width() + original_indent_width
-                            .saturating_sub(min_prefix_space_width);
-                        let new_indent = Indent::from_width(context.config, new_indent_width);
-                        format!("{}{}", new_indent.to_string(context.config), line)
-                    }
-                    None => String::new(),
-                },
-            )
-            .collect::<Vec<_>>()
-            .join("\n"),
+        first_line
+            + "\n"
+            + &trimmed_lines
+                .iter()
+                .map(
+                    |&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
+                        _ if !trimmed => line.to_owned(),
+                        Some(original_indent_width) => {
+                            let new_indent_width = indent.width()
+                                + original_indent_width.saturating_sub(min_prefix_space_width);
+                            let new_indent = Indent::from_width(context.config, new_indent_width);
+                            format!("{}{}", new_indent.to_string(context.config), line)
+                        }
+                        None => String::new(),
+                    },
+                )
+                .collect::<Vec<_>>()
+                .join("\n"),
     )
 }