rustfmt is off by one for comment length after a `where` keyword

Aperta
#7,260 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Reproduce first: build rustfmt from source and run it with wrap_comments = true and comment_width = 100 on the snippet from the report, confirming the 100-column comment gets wrapped after where. The wrapping logic lives in the comment rewriting code under src/comment.rs, with the available width passed in from the rewrite sites (including where-clause handling in src/items.rs); the off-by-one is likely in how the indentation offset is subtracted from comment_width. Add a fixture next to the existing comment tests under tests/ and run them to see the new behaviour; done means the comment is left untouched while unrelated wrapping still passes.

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

Descrizione

A-comments A-where-clauses 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:

struct S<T>
where
    // This comment line is 100 columns long, yet rustfmt wraps it onto a second line: aaaaaaaaaaaaa
    T: Copy;

The comment shouldn't be changed by rustfmt, but it does change it:

> cat config.toml
wrap_comments = true
comment_width = 100

> rustfmt +nightly --version
rustfmt 1.12.0-nightly (bdf712ee87 2026-11-21)

> rustfmt +nightly --emit=stdout --config-path config.toml foo.rs
struct S<T>
where
    // This comment line is 100 columns long, yet rustfmt wraps it onto a second line:
    // aaaaaaaaaaaaa
    T: Copy;

(This is similar to #7258 and #7259, but I've filed it separately because I suspect it has a different root cause.)

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.