Skip to content

Make imports_layout = "Mixed" addressed #2671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions tests/source/configs/imports_layout/merge_mixed.rs
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions tests/target/configs/imports_layout/merge_mixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// rustfmt-imports_indent: Block
// rustfmt-merge_imports: true
// rustfmt-imports_layout: Mixed

use std::{
fmt, io, str::{self, FromStr},
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to all be on one line, any idea why it isn't?

20 changes: 5 additions & 15 deletions tests/target/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,20 @@ 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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since imports_layout is default to Mixed: https://github.com/rust-lang-nursery/rustfmt/blob/master/Configurations.md#imports_layout
so I re-fmt this part.
@nrc

yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz,
},
boo,
c,
boo, c,
};

use fooo::{
baar::foobar::{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
},
bar,
bar::*,
x,
y,
z,
bar, bar::*, x, y, z,
};

// nested imports with a single sub-tree.
Expand Down