Skip to content
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

Adjust rhs shape width to account for next line indentation #5327

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,12 @@ fn shape_from_rhs_tactic(
shape: Shape,
rhs_tactic: RhsTactics,
) -> Option<Shape> {
let using_version_2 = context.config.version() == Version::Two;
let no_indent = shape.indent.width() == 0;
match rhs_tactic {
RhsTactics::ForceNextLineWithoutIndent if no_indent && using_version_2 => shape
.with_max_width(context.config)
.sub_width(context.config.tab_spaces()),
RhsTactics::ForceNextLineWithoutIndent => shape
.with_max_width(context.config)
.sub_width(shape.indent.width()),
Expand Down
19 changes: 19 additions & 0 deletions tests/source/issue_5321.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// rustfmt-version: Two

trait AllTheOthers1: Trait3 + Trait4 + Trait5 + Trait6 + Trait7 + Trait8 + Trait9 + Trait10 + Trait11 + Trait12 + Trait14
{
}

trait AllTheOthers2: Trait4 + Trait5 + Trait6 + Trait7 + Trait8 + Trait9 + Trait10 + Trait11 + Trait12 + Trait13 + Trait15
{
}

mod Module {
trait AllTheOthers3: Trait5 + Trait6 + Trait7 + Trait8 + Trait9 + Trait10 + Trait11 + Trait12 + Trait13 + Trait14
{
}

trait AllTheOthers4: Trait6 + Trait7 + Trait8 + Trait9 + Trait10 + Trait11 + Trait12 + Trait13 + Trait14 + Trait15
{
}
}
52 changes: 52 additions & 0 deletions tests/target/issue_5321.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// rustfmt-version: Two

trait AllTheOthers1:
Trait3
+ Trait4
+ Trait5
+ Trait6
+ Trait7
+ Trait8
+ Trait9
+ Trait10
+ Trait11
+ Trait12
+ Trait14
{
}

trait AllTheOthers2:
Trait4
+ Trait5
+ Trait6
+ Trait7
+ Trait8
+ Trait9
+ Trait10
+ Trait11
+ Trait12
+ Trait13
+ Trait15
{
}

mod Module {
trait AllTheOthers3:
Trait5 + Trait6 + Trait7 + Trait8 + Trait9 + Trait10 + Trait11 + Trait12 + Trait13 + Trait14
{
}

trait AllTheOthers4:
Trait6
+ Trait7
+ Trait8
+ Trait9
+ Trait10
+ Trait11
+ Trait12
+ Trait13
+ Trait14
+ Trait15
{
}
}