Merge pull request #3511 from topecongiro/issue3498

Avoid overflowing item with attributes
This commit is contained in:
Seiichi Uchida 2019-04-17 11:40:00 -07:00 committed by GitHub
commit 5dd042c152
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 0 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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")]
{});
}

View file

@ -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")]
{},
);
}