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;
}
_ => {}
} 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(' ');
--- /dev/null
+// 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,
+];
--- /dev/null
+// 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,
+];