Skip to content

Commit d3e578b

Browse files
committed
Avoid overflowing item if it has attributes
1 parent 37959a9 commit d3e578b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ pub fn can_be_overflowed_expr(
13431343
args_len: usize,
13441344
) -> bool {
13451345
match expr.node {
1346+
_ if !expr.attrs.is_empty() => false,
13461347
ast::ExprKind::Match(..) => {
13471348
(context.use_block_indent() && args_len == 1)
13481349
|| (context.config.indent_style() == IndentStyle::Visual && args_len > 1)

src/overflow.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ impl<'a> Spanned for OverflowableItem<'a> {
9191
}
9292

9393
impl<'a> OverflowableItem<'a> {
94+
fn has_attrs(&self) -> bool {
95+
match self {
96+
OverflowableItem::Expr(ast::Expr { attrs, .. })
97+
| OverflowableItem::GenericParam(ast::GenericParam { attrs, .. }) => !attrs.is_empty(),
98+
OverflowableItem::StructField(ast::StructField { attrs, .. }) => !attrs.is_empty(),
99+
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => !expr.attrs.is_empty(),
100+
OverflowableItem::MacroArg(MacroArg::Item(item)) => !item.attrs.is_empty(),
101+
_ => false,
102+
}
103+
}
104+
94105
pub fn map<F, T>(&self, f: F) -> T
95106
where
96107
F: Fn(&dyn IntoOverflowableItem<'a>) -> T,
@@ -447,6 +458,7 @@ impl<'a> Context<'a> {
447458
// 1 = "("
448459
let combine_arg_with_callee = self.items.len() == 1
449460
&& self.items[0].is_expr()
461+
&& !self.items[0].has_attrs()
450462
&& self.ident.len() < self.context.config.tab_spaces();
451463
let overflow_last = combine_arg_with_callee || can_be_overflowed(self.context, &self.items);
452464

0 commit comments

Comments
 (0)