Fix an anomaly with comments and array literals

Closes #2842
This commit is contained in:
Nick Cameron 2018-07-17 15:38:50 +12:00
parent 9038da6df0
commit b28a0cd6e6
3 changed files with 42 additions and 5 deletions

View File

@ -297,17 +297,15 @@ where
if formatting.ends_with_newline {
trailing_separator = true;
}
} else if line_len > 0 {
result.push(' ');
line_len += 1;
}
if last && formatting.ends_with_newline {
separate = formatting.trailing_separator != SeparatorTactic::Never;
}
if line_len > 0 {
result.push(' ');
line_len += 1;
}
line_len += total_width;
}
_ => {}
@ -341,6 +339,8 @@ where
} else {
result.push('\n');
result.push_str(indent_str);
// This is the width of the item (without comments).
line_len = item.item.as_ref().map_or(0, |str| str.len());
}
} else {
result.push(' ');

View File

@ -0,0 +1,19 @@
// Issue 2842
// The comment should not make the last line shorter
static XXX: [i8; 64] = [
1, // Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
static XXX: [i8; 64] = [
1,
// Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
static XXX: [i8; 64] = [
1,
// Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];

View File

@ -0,0 +1,18 @@
// Issue 2842
// The comment should not make the last line shorter
static XXX: [i8; 64] = [
1, // Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
static XXX: [i8; 64] = [
1, // Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
static XXX: [i8; 64] = [
1, // Comment
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
];