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

未关闭
#7,076 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
tooling

调研方向

从 src/visitor.rs 中链接的跳过范围计算处开始,并使用报告中的 rustfmt 命令和 Rust 代码片段重现该问题。跟踪换行后的行如何影响 formatter 访问的行数。完成的标准是:未跳过的长行仍会产生错误,而 #[rustfmt::skip] 行不会产生错误。

由索引模型根据 Issue 内容生成。

描述

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)
主要语言
Rust
星标
7.1k
派生
1.2k
平均合并
1 天 4 小时
30 天内合并 PR
20

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/rustfmt 的其他 Issue

查看 rust-lang/rustfmt 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。