Skip to content

Commit 0dd0cc1

Browse files
alobbnrc
authored andcommitted
Break use statements into multiple lines (#1407)
This fixes how line lengths for use statements with multiple items don't extend beyond the maximum line length. Fixes #1400
1 parent f96e56c commit 0dd0cc1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/imports.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ pub fn rewrite_use_list(shape: Shape,
323323
_ => (),
324324
}
325325

326-
// 2 = {}
327-
let remaining_width = shape.width.checked_sub(path_str.len() + 2).unwrap_or(0);
326+
let colons_offset = if path_str.is_empty() { 0 } else { 2 };
327+
328+
// 2 = "{}"
329+
let remaining_width = shape.width.checked_sub(path_str.len() + 2 + colons_offset).unwrap_or(0);
328330

329331
let mut items = {
330332
// Dummy value, see explanation below.
@@ -351,20 +353,18 @@ pub fn rewrite_use_list(shape: Shape,
351353
items[1..].sort_by(|a, b| a.item.cmp(&b.item));
352354
}
353355

354-
let colons_offset = if path_str.is_empty() { 0 } else { 2 };
355356

356357
let tactic = definitive_tactic(&items[first_index..],
357358
::lists::ListTactic::Mixed,
358359
remaining_width);
360+
359361
let fmt = ListFormatting {
360362
tactic: tactic,
361363
separator: ",",
362364
trailing_separator: SeparatorTactic::Never,
363-
// FIXME This is too conservative, and will not use all width
364-
// available
365-
// (loose 1 column (";"))
365+
// Add one to the indent to account for "{"
366366
shape: Shape::legacy(remaining_width,
367-
shape.indent + path_str.len() + 1 + colons_offset),
367+
shape.indent + path_str.len() + colons_offset + 1),
368368
ends_with_newline: false,
369369
config: context.config,
370370
};
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
2+
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd};
3+
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc,
4+
ddddddddd};

0 commit comments

Comments
 (0)