rust-lang / rust-lang/rustfmt

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

Open
#7,076 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-rustfmt::skip C-bug E-hard E-medium
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/visitor.rs at the linked skip-range calculation and reproduce the issue with the rustfmt command and Rust snippet from the report. Trace how wrapped lines affect the formatter's visited-line count. Done means the unskipped long line still produces an error while the #[rustfmt::skip] line does not.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.