`struct_field_align_threshold` ignores inline comments before struct literal fields
I maintainer di solito rispondono entro 1 giorno
@tkr-sh ci sta già lavorando.
Dal 24/10/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Rust
- Stelle
- 7.1k
- Fork
- 1.2k
- Merge medio
- 1g 4h
- PR unite (30g)
- 20
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rustfmt
-
A-config C-bug SO-print-config
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
A-Unicode C-bug P-low
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
rust-lang/rustfmt#7210 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-lang/rustfmt#7173 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A-comments C-bug only-with-option UO-indent_style
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Fix `first_line_width` to be tab-awareForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaA-tabs A-whitespace C-bug SO-hard_tabs
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rustfmt
Issue simili
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug core-lang
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Windows microphone listing treats words in a device name as DirectShow labelsForse già presa @Sujal-chaudhary l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clipy-recorder/clipy#447 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
max-sixty/worktrunk#4939 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno