Merge pull request #2599 from topecongiro/issue-2596
Use multiple lines for imports list which exceeds max width
This commit is contained in:
commit
4b2160e1b2
4 changed files with 18 additions and 6 deletions
|
|
@ -497,7 +497,8 @@ fn rewrite_nested_use_tree(
|
|||
|
||||
let list_str = write_list(&list_items, &fmt)?;
|
||||
|
||||
let result = if list_str.contains('\n') && context.config.imports_indent() == IndentStyle::Block
|
||||
let result = if (list_str.contains('\n') || list_str.len() > remaining_width)
|
||||
&& context.config.imports_indent() == IndentStyle::Block
|
||||
{
|
||||
format!(
|
||||
"{{\n{}{}\n{}}}",
|
||||
|
|
|
|||
11
src/lists.rs
11
src/lists.rs
|
|
@ -172,11 +172,10 @@ where
|
|||
|
||||
let limit = match tactic {
|
||||
_ if pre_line_comments => return DefinitiveListTactic::Vertical,
|
||||
ListTactic::Mixed => return DefinitiveListTactic::Mixed,
|
||||
ListTactic::Horizontal => return DefinitiveListTactic::Horizontal,
|
||||
ListTactic::Vertical => return DefinitiveListTactic::Vertical,
|
||||
ListTactic::LimitedHorizontalVertical(limit) => ::std::cmp::min(width, limit),
|
||||
ListTactic::HorizontalVertical => width,
|
||||
ListTactic::Mixed | ListTactic::HorizontalVertical => width,
|
||||
};
|
||||
|
||||
let (sep_count, total_width) = calculate_width(items.clone());
|
||||
|
|
@ -188,7 +187,10 @@ where
|
|||
{
|
||||
DefinitiveListTactic::Horizontal
|
||||
} else {
|
||||
DefinitiveListTactic::Vertical
|
||||
match tactic {
|
||||
ListTactic::Mixed => DefinitiveListTactic::Mixed,
|
||||
_ => DefinitiveListTactic::Vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -278,8 +280,7 @@ where
|
|||
|
||||
if last && formatting.ends_with_newline {
|
||||
match formatting.trailing_separator {
|
||||
SeparatorTactic::Always => separate = true,
|
||||
SeparatorTactic::Vertical if result.contains('\n') => separate = true,
|
||||
SeparatorTactic::Always | SeparatorTactic::Vertical => separate = true,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
tests/source/imports_block_indent.rs
Normal file
4
tests/source/imports_block_indent.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// rustfmt-imports_indent: Block
|
||||
|
||||
// #2569
|
||||
use apns2::request::notification::{Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder};
|
||||
6
tests/target/imports_block_indent.rs
Normal file
6
tests/target/imports_block_indent.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// rustfmt-imports_indent: Block
|
||||
|
||||
// #2569
|
||||
use apns2::request::notification::{
|
||||
Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue