diff --git a/src/imports.rs b/src/imports.rs index 669cf795bc74..05b10519d45d 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -693,19 +693,20 @@ fn rewrite_nested_use_tree( _ => false, }) }); - let (tactic, remaining_width) = if has_nested_list { - (DefinitiveListTactic::Vertical, 0) + + let remaining_width = if has_nested_list { + 0 } else { - let remaining_width = shape.width.checked_sub(2).unwrap_or(0); - let tactic = definitive_tactic( - &list_items, - context.config.imports_layout(), - Separator::Comma, - remaining_width, - ); - (tactic, remaining_width) + shape.width.checked_sub(2).unwrap_or(0) }; + let tactic = definitive_tactic( + &list_items, + context.config.imports_layout(), + Separator::Comma, + remaining_width, + ); + let ends_with_newline = context.config.imports_indent() == IndentStyle::Block && tactic != DefinitiveListTactic::Horizontal; let fmt = ListFormatting { diff --git a/tests/source/configs/imports_layout/merge_mixed.rs b/tests/source/configs/imports_layout/merge_mixed.rs new file mode 100644 index 000000000000..bd09079a5950 --- /dev/null +++ b/tests/source/configs/imports_layout/merge_mixed.rs @@ -0,0 +1,6 @@ +// rustfmt-imports_indent: Block +// rustfmt-merge_imports: true +// rustfmt-imports_layout: Mixed + +use std::{fmt, io, str}; +use std::str::FromStr; diff --git a/tests/target/configs/imports_layout/merge_mixed.rs b/tests/target/configs/imports_layout/merge_mixed.rs new file mode 100644 index 000000000000..d67979840d0e --- /dev/null +++ b/tests/target/configs/imports_layout/merge_mixed.rs @@ -0,0 +1,7 @@ +// rustfmt-imports_indent: Block +// rustfmt-merge_imports: true +// rustfmt-imports_layout: Mixed + +use std::{ + fmt, io, str::{self, FromStr}, +}; diff --git a/tests/target/imports.rs b/tests/target/imports.rs index 2e195520a068..b3d78e609fea 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -80,18 +80,12 @@ use self::unix::{}; // nested imports use foo::{ - a, - b, + a, b, bar::{ - baz, - foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, - qux, - xxxxxxxxxxx, - yyyyyyyyyyyyy, - zzzzzzzzzzzzzzzz, + baz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, qux, xxxxxxxxxxx, + yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, }, - boo, - c, + boo, c, }; use fooo::{ @@ -99,11 +93,7 @@ use fooo::{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, }, - bar, - bar::*, - x, - y, - z, + bar, bar::*, x, y, z, }; // nested imports with a single sub-tree.