about summary refs log tree commit diff
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2019-04-14 20:45:04 +0900
committertopecongiro <seuchida@gmail.com>2019-04-14 20:45:04 +0900
commitd3e578b1312b2258f0a8ee24c15416affcaf1ce1 (patch)
tree151728ae79ee068c87f617cd84e5b2f69e009223
parent37959a9da7d49838dfeb86479ebe88d78f5c0a49 (diff)
Avoid overflowing item if it has attributes
-rw-r--r--src/expr.rs1
-rw-r--r--src/overflow.rs12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 90cbba334f1..ff95ee41d02 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1343,6 +1343,7 @@ pub fn can_be_overflowed_expr(
     args_len: usize,
 ) -> bool {
     match expr.node {
+        _ if !expr.attrs.is_empty() => false,
         ast::ExprKind::Match(..) => {
             (context.use_block_indent() && args_len == 1)
                 || (context.config.indent_style() == IndentStyle::Visual && args_len > 1)
diff --git a/src/overflow.rs b/src/overflow.rs
index ac425b591aa..bd23d955aae 100644
--- a/src/overflow.rs
+++ b/src/overflow.rs
@@ -91,6 +91,17 @@ impl<'a> Spanned for OverflowableItem<'a> {
 }
 
 impl<'a> OverflowableItem<'a> {
+    fn has_attrs(&self) -> bool {
+        match self {
+            OverflowableItem::Expr(ast::Expr { attrs, .. })
+            | OverflowableItem::GenericParam(ast::GenericParam { attrs, .. }) => !attrs.is_empty(),
+            OverflowableItem::StructField(ast::StructField { attrs, .. }) => !attrs.is_empty(),
+            OverflowableItem::MacroArg(MacroArg::Expr(expr)) => !expr.attrs.is_empty(),
+            OverflowableItem::MacroArg(MacroArg::Item(item)) => !item.attrs.is_empty(),
+            _ => false,
+        }
+    }
+
     pub fn map<F, T>(&self, f: F) -> T
     where
         F: Fn(&dyn IntoOverflowableItem<'a>) -> T,
@@ -447,6 +458,7 @@ impl<'a> Context<'a> {
         // 1 = "("
         let combine_arg_with_callee = self.items.len() == 1
             && self.items[0].is_expr()
+            && !self.items[0].has_attrs()
             && self.ident.len() < self.context.config.tab_spaces();
         let overflow_last = combine_arg_with_callee || can_be_overflowed(self.context, &self.items);