Fix supertrait wrapping when within max_width#6814
Fix supertrait wrapping when within max_width#6814xonx4l wants to merge 2 commits intorust-lang:mainfrom
Conversation
| @@ -0,0 +1,24 @@ | |||
| // rustfmt-max_width: 100 | |||
There was a problem hiding this comment.
Question (for other rustfmt maintainers): I believe max_width is a stable option with a default value of 100.
- This impacts a stable option.
- This impacts formatting of the default value of a stable option.
- The stable code is already formatted.
I believe this fix needs to be gated behind a style-edition.
There was a problem hiding this comment.
You are right . I think gating this behind StyleEdition::2024 will be good and won't regress formatting . Thanks!
There was a problem hiding this comment.
I think you will need to gate it behind StyleEdition::2027, StyleEdition::2024 is already the default inferred style edition if crate Rust edition is 2024.
There was a problem hiding this comment.
Gated it behind StyleEdition::2027. Thanks!
|
To open a discussion: I also had a look into this issue and came up with another approach: c58a7c1 (but saw this was opened before creating a PR) that passes the test suite and so I don't think that change would require a version gate |
This PR fixes an issue where supertraits were being forced to a new line even when they fit within the configured max_width as mentioned in #6809
Proposed Solution:
Use the original indented
Shapefor trait bounds instead of a manually reduced one preventing the "double-width reduction" math error informat_trait. This allowsrewrite_assign_rhsto correctly calculate available horizontal space, keeping bounds on the same line when they fit withinmax_width.The Changes -
Updated format_trait in src/items.rs to use the original indented offset and full available width for the bounds_shape.
Added rewrite_assign_rhs to handle the width reduction naturally based on the actual length of the trait header (lhs).
Replaced the manual newline logic with the dynamic wrapping provided by RhsAssignKind::Bounds.