mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 13:13:17 +00:00
Merge pull request #1822 from topecongiro/issue-1172
Remove newlines between list elements for expressions
This commit is contained in:
commit
1f991d00e0
@ -527,6 +527,7 @@ where
|
||||
},
|
||||
shape: nested_shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&items, &fmt));
|
||||
@ -602,6 +603,7 @@ fn rewrite_closure_fn_decl(
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: arg_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
@ -1673,6 +1675,7 @@ fn rewrite_match_pattern(
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: pat_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let pats_str = try_opt!(write_list(&items, &fmt));
|
||||
@ -2165,6 +2168,7 @@ where
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: context.use_block_indent() && tactic == DefinitiveListTactic::Vertical,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2760,6 +2764,7 @@ where
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
|
@ -478,6 +478,7 @@ fn rewrite_use_list(
|
||||
},
|
||||
shape: nested_shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&items[first_index..], &fmt));
|
||||
|
@ -477,6 +477,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
trailing_separator: self.config.trailing_comma(),
|
||||
shape: shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: self.config,
|
||||
};
|
||||
|
||||
@ -2252,6 +2253,7 @@ fn rewrite_args(
|
||||
},
|
||||
shape: Shape::legacy(budget, indent),
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_layout()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2425,6 +2427,7 @@ where
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.generics_indent()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2538,6 +2541,7 @@ fn rewrite_where_clause_rfc_style(
|
||||
trailing_separator: comma_tactic,
|
||||
shape: clause_shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let preds_str = try_opt!(write_list(&items.collect::<Vec<_>>(), &fmt));
|
||||
@ -2639,6 +2643,7 @@ fn rewrite_where_clause(
|
||||
trailing_separator: comma_tactic,
|
||||
shape: Shape::legacy(budget, offset),
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.where_pred_indent()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let preds_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
|
@ -65,6 +65,8 @@ pub struct ListFormatting<'a> {
|
||||
// Non-expressions, e.g. items, will have a new line at the end of the list.
|
||||
// Important for comment styles.
|
||||
pub ends_with_newline: bool,
|
||||
// Remove newlines between list elements for expressions.
|
||||
pub preserve_newline: bool,
|
||||
pub config: &'a Config,
|
||||
}
|
||||
|
||||
@ -342,7 +344,9 @@ where
|
||||
item_max_width = None;
|
||||
}
|
||||
|
||||
if !last && tactic == DefinitiveListTactic::Vertical && item.new_lines {
|
||||
if formatting.preserve_newline && !last && tactic == DefinitiveListTactic::Vertical &&
|
||||
item.new_lines
|
||||
{
|
||||
item_max_width = None;
|
||||
result.push('\n');
|
||||
}
|
||||
@ -675,6 +679,7 @@ pub fn struct_lit_formatting<'a>(
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
}
|
||||
}
|
||||
|
@ -360,6 +360,7 @@ where
|
||||
},
|
||||
shape: list_shape,
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.fn_call_style()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
|
@ -229,6 +229,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|
||||
trailing_separator: context.config.trailing_comma(),
|
||||
shape: item_shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
write_list(&items, &fmt)
|
||||
|
@ -819,6 +819,7 @@ impl Rewrite for ast::MetaItem {
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: item_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
format!("{}({})", name, try_opt!(write_list(&item_vec, &fmt)))
|
||||
|
@ -327,3 +327,31 @@ fn issue1749() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #1172
|
||||
fn newlines_between_list_like_expr() {
|
||||
foo(
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||
);
|
||||
|
||||
vec![
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||
];
|
||||
|
||||
match x {
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy |
|
||||
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz => foo(a, b, c),
|
||||
_ => bar(),
|
||||
};
|
||||
}
|
||||
|
@ -391,3 +391,25 @@ fn issue1749() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #1172
|
||||
fn newlines_between_list_like_expr() {
|
||||
foo(
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||
);
|
||||
|
||||
vec![
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||
];
|
||||
|
||||
match x {
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy |
|
||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz => foo(a, b, c),
|
||||
_ => bar(),
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user