mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
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
This commit is contained in:
parent
f96e56c3a0
commit
0dd0cc1941
@ -323,8 +323,10 @@ pub fn rewrite_use_list(shape: Shape,
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2 = {}
|
let colons_offset = if path_str.is_empty() { 0 } else { 2 };
|
||||||
let remaining_width = shape.width.checked_sub(path_str.len() + 2).unwrap_or(0);
|
|
||||||
|
// 2 = "{}"
|
||||||
|
let remaining_width = shape.width.checked_sub(path_str.len() + 2 + colons_offset).unwrap_or(0);
|
||||||
|
|
||||||
let mut items = {
|
let mut items = {
|
||||||
// Dummy value, see explanation below.
|
// Dummy value, see explanation below.
|
||||||
@ -351,20 +353,18 @@ pub fn rewrite_use_list(shape: Shape,
|
|||||||
items[1..].sort_by(|a, b| a.item.cmp(&b.item));
|
items[1..].sort_by(|a, b| a.item.cmp(&b.item));
|
||||||
}
|
}
|
||||||
|
|
||||||
let colons_offset = if path_str.is_empty() { 0 } else { 2 };
|
|
||||||
|
|
||||||
let tactic = definitive_tactic(&items[first_index..],
|
let tactic = definitive_tactic(&items[first_index..],
|
||||||
::lists::ListTactic::Mixed,
|
::lists::ListTactic::Mixed,
|
||||||
remaining_width);
|
remaining_width);
|
||||||
|
|
||||||
let fmt = ListFormatting {
|
let fmt = ListFormatting {
|
||||||
tactic: tactic,
|
tactic: tactic,
|
||||||
separator: ",",
|
separator: ",",
|
||||||
trailing_separator: SeparatorTactic::Never,
|
trailing_separator: SeparatorTactic::Never,
|
||||||
// FIXME This is too conservative, and will not use all width
|
// Add one to the indent to account for "{"
|
||||||
// available
|
|
||||||
// (loose 1 column (";"))
|
|
||||||
shape: Shape::legacy(remaining_width,
|
shape: Shape::legacy(remaining_width,
|
||||||
shape.indent + path_str.len() + 1 + colons_offset),
|
shape.indent + path_str.len() + colons_offset + 1),
|
||||||
ends_with_newline: false,
|
ends_with_newline: false,
|
||||||
config: context.config,
|
config: context.config,
|
||||||
};
|
};
|
||||||
|
4
tests/target/import-fencepost-length.rs
Normal file
4
tests/target/import-fencepost-length.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||||
|
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd};
|
||||||
|
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc,
|
||||||
|
ddddddddd};
|
Loading…
Reference in New Issue
Block a user