diff --git a/src/items.rs b/src/items.rs index 2c5fcf09c9f..746fe4b9fe8 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1190,15 +1190,14 @@ pub(crate) fn format_trait( if contains_comment(snippet) { return Err(RewriteError::Unknown); } + let bounds_shape = if context.config.style_edition() >= StyleEdition::Edition2027 { + Shape::indented(offset, context.config) + } else { + Shape::indented(offset, context.config).sub_width(result.len(), ident.span)? + }; - result = rewrite_assign_rhs_with( - context, - result + ":", - bounds, - shape, - &RhsAssignKind::Bounds, - RhsTactics::ForceNextLineWithoutIndent, - )?; + let lhs = result + ":"; + result = rewrite_assign_rhs(context, lhs, bounds, &RhsAssignKind::Bounds, bounds_shape)?; } // Rewrite where-clause. diff --git a/tests/source/issue-6809/supertraits.rs b/tests/source/issue-6809/supertraits.rs new file mode 100644 index 00000000000..850086f2614 --- /dev/null +++ b/tests/source/issue-6809/supertraits.rs @@ -0,0 +1,24 @@ +// rustfmt-max_width: 50 + +// line below is 30 chars +pub(super) unsafe trait A: B { + fn foo(); +} + +// line below is 36 chars +pub unsafe trait Trait2: A + B + C { + fn foo(); +} + +// line below is 43 chars +pub trait TraitThree: Super1 + Super2 + X { + fn foo(); +} + +// line below is 47 chars +trait TraitNumberFour: Super1 + Super2 + Abcd { + fn foo(); +} + +// line below is correctly not wrapped +pub const THIS_LINE_IS_50_CHARS: usize = 12345678; diff --git a/tests/source/issue-6809/supertraits_max_width_100.rs b/tests/source/issue-6809/supertraits_max_width_100.rs new file mode 100644 index 00000000000..222f89c5af8 --- /dev/null +++ b/tests/source/issue-6809/supertraits_max_width_100.rs @@ -0,0 +1,25 @@ +// rustfmt-style_edition: 2027 +// rustfmt-max_width: 100 + +// line below is 80 chars +pub(super) unsafe trait ALetsMakeThisLineLongerByExactlyFiftyCharacters1234: B { + fn foo(); +} + +// line below is 86 chars +pub unsafe trait Trait2LetsMakeThisLineLongerByExactlyFiftyCharacters1234: A + B + C { + fn foo(); +} + +// line below is 93 chars +pub trait TraitThreeLetsMakeThisLineLongerByExactlyFiftyCharacters1234: Super1 + Super2 + X { + fn foo(); +} + +// line below is 97 chars +trait TraitNumberFourLetsMakeThisLineLongerByExactlyFiftyCharacters1234: Super1 + Super2 + Abcd { + fn foo(); +} + +// line below is correctly not wrapped +pub const THIS_LINE_IS_100_CHARS: &str = "12345678901234567890123456789012345678901234567890123456"; diff --git a/tests/target/issue-6809/supertraits.rs b/tests/target/issue-6809/supertraits.rs new file mode 100644 index 00000000000..850086f2614 --- /dev/null +++ b/tests/target/issue-6809/supertraits.rs @@ -0,0 +1,24 @@ +// rustfmt-max_width: 50 + +// line below is 30 chars +pub(super) unsafe trait A: B { + fn foo(); +} + +// line below is 36 chars +pub unsafe trait Trait2: A + B + C { + fn foo(); +} + +// line below is 43 chars +pub trait TraitThree: Super1 + Super2 + X { + fn foo(); +} + +// line below is 47 chars +trait TraitNumberFour: Super1 + Super2 + Abcd { + fn foo(); +} + +// line below is correctly not wrapped +pub const THIS_LINE_IS_50_CHARS: usize = 12345678; diff --git a/tests/target/issue-6809/supertraits_max_width_100.rs b/tests/target/issue-6809/supertraits_max_width_100.rs new file mode 100644 index 00000000000..222f89c5af8 --- /dev/null +++ b/tests/target/issue-6809/supertraits_max_width_100.rs @@ -0,0 +1,25 @@ +// rustfmt-style_edition: 2027 +// rustfmt-max_width: 100 + +// line below is 80 chars +pub(super) unsafe trait ALetsMakeThisLineLongerByExactlyFiftyCharacters1234: B { + fn foo(); +} + +// line below is 86 chars +pub unsafe trait Trait2LetsMakeThisLineLongerByExactlyFiftyCharacters1234: A + B + C { + fn foo(); +} + +// line below is 93 chars +pub trait TraitThreeLetsMakeThisLineLongerByExactlyFiftyCharacters1234: Super1 + Super2 + X { + fn foo(); +} + +// line below is 97 chars +trait TraitNumberFourLetsMakeThisLineLongerByExactlyFiftyCharacters1234: Super1 + Super2 + Abcd { + fn foo(); +} + +// line below is correctly not wrapped +pub const THIS_LINE_IS_100_CHARS: &str = "12345678901234567890123456789012345678901234567890123456";