`#[rustfmt::skip]` attribute skips extra lines

Aperta
#7,076 4 commenti 1 reazione 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
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
tooling

Direzione di ricerca

Inizia in src/visitor.rs, nel calcolo collegato dell’intervallo da saltare, e riproduci il problema con il comando rustfmt e lo snippet Rust del report. Traccia come le righe a capo influiscono sul conteggio delle righe visitate dal formatter. Il lavoro è completato quando la riga lunga non saltata continua a produrre un errore, mentre la riga #[rustfmt::skip] non lo produce.

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

Descrizione

A-rustfmt::skip A-whitespace C-bug E-hard E-medium

Summary

Kind of the opposite to https://github.com/rust-lang/rustfmt/issues/6954 (but I think they need to be addressed together).

The cause is, when calculating the skip range we use:

  • The line after the attributes (the start)
  • The count of lines the formatter saw (the end)

But when the formatter splits one line into several, the count of lines visited increases, so the skip range extends much further.

I tried to format this code:

fn foo() {
    some.very().very().very().very().very().very().long().method().call().chain().that().will().wrap();
    println!("This is a very long line, it will easily go past max_width. PADDING                   ");

    #[rustfmt::skip]
    println!("This is a very long line, it will easily go past max_width. PADDING                   ");
}
Expected behavior
  1. The very long method chain is split up
  2. There is an error because the first println line exceeds the line length limit
  3. There's no error for the second println line, it exceeds the length limit but is skipped
Actual behavior

The second point above does not hold, there is no error about the extra long line

Configuration

N/A: run with any empty config

rustfmt cli options used (if applicable):

$ rustfmt --config max_width=70 --config error_on_unformatted=true --config error_on_line_overflow=true

Reproduction Steps

Run the rustfmt command above on the file contents also above

$ rustfmt --version
rustfmt 1.9.0-nightly (eff8269f79 2026-07-18)
# also reproduced on recent dev build
$ cargo run --quiet --bin rustfmt -- --version
rustfmt 1.10.0-nightly (138684c552 2026-08-25)
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.