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(&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")] + {}, + ); +}