`struct_field_align_threshold` ignores inline comments before struct literal fields
Les mainteneurs répondent en général sous 1 jour
@tkr-sh y travaille déjà.
Depuis le 24/10/2026.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
Piste de recherche
Start by reading the struct_field_align_threshold alignment logic and its shared handling of ast::FieldDef, which the issue says also affects struct definitions. Reproduce the shown struct literal case with a block comment before a field, then check how the formatter calculates the aligned value column. Done when the chosen comment behavior is consistent and covered for both struct literals and definitions.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hello,
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
- Langage dominant
- Rust
- Étoiles
- 7.1k
- Forks
- 1.2k
- Merge moyen
- 1 j 4 h
- PR mergées (30 j)
- 20
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rust-lang/rustfmt
-
A-config C-bug SO-print-config
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
Les mainteneurs répondent en général sous 1 jour
-
A-Unicode C-bug P-low
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
rust-lang/rustfmt#7210 · 5 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
rust-lang/rustfmt#7173 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
A-comments C-bug only-with-option UO-indent_style
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Fix `first_line_width` to be tab-awarePeut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. OuverteA-tabs A-whitespace C-bug SO-hard_tabs
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rust-lang/rustfmt
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
tamatebako/tebako#1155 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
swc-project/swc-next-issues#1148 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
registrystack/registry-stack#2828 ·
Les mainteneurs répondent en général sous 1 jour
-
agent:triaged arch-audit bug priority:p1
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
SocketDev/socket-patch#2364 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug P2
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour