address reviewer comments

This commit is contained in:
Nick Cameron 2018-07-12 22:21:07 +12:00
parent 7a76e5b1b4
commit 229a55248b
3 changed files with 16 additions and 8 deletions

View file

@ -419,7 +419,8 @@ where
if first_line_width(&formatted_comment)
+ last_line_width(&result)
+ comment_alignment
+ 1 > formatting.config.max_width()
+ 1
> formatting.config.max_width()
{
item_max_width = None;
formatted_comment = rewrite_post_comment(&mut item_max_width)?;

View file

@ -69,10 +69,7 @@ fn rewrite_pairs_one_line<T: Rewrite>(
let mut result = String::new();
let base_shape = shape.block();
for (e, s) in list.list[..list.list.len()]
.iter()
.zip(list.separators.iter())
{
for (e, s) in list.list.iter().zip(list.separators.iter()) {
let cur_shape = base_shape.offset_left(last_line_width(&result))?;
let rewrite = e.rewrite(context, cur_shape)?;
@ -137,7 +134,15 @@ fn rewrite_pairs_multiline<T: Rewrite>(
result.push_str(&rewrite);
for (e, s) in list.list[1..].iter().zip(list.separators.iter()) {
if trimmed_last_line_width(&result) <= context.config.tab_spaces() {
// The following test checks if we should keep two subexprs on the same
// line. We do this if not doing so would create an orphan and there is
// enough space to do so.
let offset = if result.contains('\n') {
0
} else {
shape.used_width()
};
if last_line_width(&result) + offset <= nested_shape.used_width() {
// We must snuggle the next line onto the previous line to avoid an orphan.
if let Some(line_shape) =
shape.offset_left(s.len() + 2 + trimmed_last_line_width(&result))

View file

@ -22,7 +22,8 @@ fn foo() -> bool {
trivial_value,
);
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ a + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ a
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaa);
{
@ -514,5 +515,6 @@ fn issue_2802() {
* a_very_specific_length(specific_length_arg)
* very_specific_length(Foo {
a: some_much_much_longer_value,
}) * some_value
})
* some_value
}