rustfmt gives legal length comments a ragged edge in argument lists

Aperta
#7,167 8 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@matthewhughes934 ci sta già lavorando.

Dal 9/10/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
tooling

Direzione di ricerca

Start by reproducing the reported output with the nested Rust argument-list example and the shown rustfmt configuration (wrap_comments = true, comment_width = 100). Read rustfmt's comment-wrapping implementation and its tests for comments in argument lists; the issue does not name specific files. Done means formatting preserves the reported legal-length comment without producing the ragged reflow shown.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-comments C-bug UO-comment_width UO-wrap_comments

Here is a Rust file with no line longer than 100 bytes, and one line equal to 100 bytes:

fn main() {
    if true {
        if true {
            if true {
                if true {
                    if true {
                        if true {
                            foo(
                                // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
                                // eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
                                // enim ad minim veniam, quis nostrud exercitation ullamco laboris
                                // nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
                                // reprehenderit in voluptate velit esse cillum dolore eu fugiat
                                // nulla pariatur.
                                1,
                            );
                        }
                    }
                }
            }
        }
    }
}

The comment shouldn't be changed by rustfmt, but it does change it, giving it a very ragged edge:

> cat config.toml
wrap_comments = true
comment_width = 100

> rustfmt +nightly --version
rustfmt 1.11.0-nightly (1d81eb4ad9 2026-10-07)

> rustfmt +nightly --emit=stdout --config-path config.toml foo.rs
fn main() {
    if true {
        if true {
            if true {
                if true {
                    if true {
                        if true {
                            foo(
                                // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
                                // eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
                                // enim ad minim veniam, quis nostrud exercitation ullamco laboris
                                // nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
                                // in reprehenderit in voluptate
                                // velit esse cillum dolore eu fugiat
                                // nulla pariatur.
                                1,
                            );
                        }
                    }
                }
            }
        }
    }
}
Lingua principale
Rust
Stelle
7.1k
Fork
1.2k
Merge medio
1g 4h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rustfmt

Tutte le issue di rust-lang/rustfmt

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.