You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
struct_field_align_threshold ignores inline comments before struct literal fields #7204
This is a separate issue from #7203 that I noticed while working on #7202
With struct_field_align_threshold, a block comment before a struct literal field can be kept on the same line as the field name, but its width is not included in the alignment calculation, so the values do not line up.
so
Self{a:1,/* a comment */longer:2,}
gives
Self{a:1,/* a comment */longer:2,}
I think that this is kind of confusing because it doesn't align the field values to the same column, while at the same time, kind of "aligning" fields:
a:1,
For me there are 5 solutions
Option A: align to total prefix length
Self{a:1,/* a comment */longer:2,}
Option B: put block comment on previous line
Self{a:1,/* a comment */longer:2,}
Option C: refuse to format using struct_field_align_threshold
Self{a:1,/* a comment */longer:2,}
Option D: current behavior
Self{a:1,/* a comment */longer:2,}
Option E: delete comment
Self{a:1,longer:2,}
which is the actual behaviour of:
Self{a:1,longer/* a comment */:/* a comment */2,}
Personally, I find Option A to be the most coherent one. If the user wants to have the block comment above because they find that the alignment takes too much width, they can just do themselves manually:
- /* a comment */ longer: 2,+ /* a comment */+ longer: 2,
Note: The alignment logic is kind of shared with ast::FieldDef, so the underlying issue also affects struct definitions
To be clear, the approach isn't decided yet, I lean toward Option A, but I'd like a maintainer to confirm first, since that's the reason #7202 was closed. I'll wait for that decision before opening a PR.
And if a maintainer would rather someone else take it, I can hand it over.
Activity
tkr-sh commentedon Oct 21, 2026
@rustbot label +UO-struct_field_align_threshold +I-poor-formatting
tkr-sh commentedon Oct 21, 2026
@rustbot label -needs-triage
GauravPawar101 commentedon Oct 24, 2026
tkr-sh commentedon Oct 24, 2026
Thanks for the interest! Since I opened this while working on #7202, I'd like to take it myself.
@rustbot claim
To be clear, the approach isn't decided yet, I lean toward Option A, but I'd like a maintainer to confirm first, since that's the reason #7202 was closed. I'll wait for that decision before opening a PR.
And if a maintainer would rather someone else take it, I can hand it over.