about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSeiichi Uchida <seuchida@gmail.com>2019-04-17 11:40:00 -0700
committerGitHub <noreply@github.com>2019-04-17 11:40:00 -0700
commit5dd042c152752aaf7eef4bb205f141ea2e65f18a (patch)
tree81d749aa4850baf7f9588905f896c762378b0325
parent760ec07978b75746f9c8de2502f2882239ed9285 (diff)
parentd3e578b1312b2258f0a8ee24c15416affcaf1ce1 (diff)
Merge pull request #3511 from topecongiro/issue3498
Avoid overflowing item with attributes
-rw-r--r--src/expr.rs1
-rw-r--r--src/overflow.rs12
-rw-r--r--tests/source/expr.rs13
-rw-r--r--tests/target/expr.rs23
4 files changed, 49 insertions, 0 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 1dbcf73618a..da1b035ad1c 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 17e04b2e7a4..8bc32fcbbc8 100644
--- a/src/overflow.rs
+++ b/src/overflow.rs
@@ -92,6 +92,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,
@@ -448,6 +459,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);
 
diff --git a/tests/source/expr.rs b/tests/source/expr.rs
index 1bb2d9014e2..be87aca83a0 100644
--- a/tests/source/expr.rs
+++ b/tests/source/expr.rs
@@ -532,3 +532,16 @@ fn issue3457() {
         }
     }
 }
+
+// #3498
+static REPRO: &[usize] = &[#[cfg(feature = "zero")]
+                           0];
+
+fn overflow_with_attr() {
+    foo(#[cfg(feature = "zero")]
+        0);
+    foobar(#[cfg(feature = "zero")]
+           0);
+    foobar(x, y, #[cfg(feature = "zero")]
+           {});
+}
diff --git a/tests/target/expr.rs b/tests/target/expr.rs
index 88de6f7fb88..e63044ea913 100644
--- a/tests/target/expr.rs
+++ b/tests/target/expr.rs
@@ -615,3 +615,26 @@ fn issue3457() {
         }
     }
 }
+
+// #3498
+static REPRO: &[usize] = &[
+    #[cfg(feature = "zero")]
+    0,
+];
+
+fn overflow_with_attr() {
+    foo(
+        #[cfg(feature = "zero")]
+        0,
+    );
+    foobar(
+        #[cfg(feature = "zero")]
+        0,
+    );
+    foobar(
+        x,
+        y,
+        #[cfg(feature = "zero")]
+        {},
+    );
+}