Merge pull request #3511 from topecongiro/issue3498
Avoid overflowing item with attributes
This commit is contained in:
commit
5dd042c152
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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")]
|
||||
{});
|
||||
}
|
||||
|
@ -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")]
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user