`max_width` is exceeded by one column when a struct literal's `{` ends the first line
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the reproducer's input.rs and rustfmt.toml, then find the rustfmt formatting tests and code that decide whether a struct literal breaks after =. Run the reproducer with max_width = 120; done means the 118-, 119-, and 120-column cases keep their first line, the two longest break after =, and no formatted line exceeds the limit.
由索引模型根据 Issue 内容生成。
描述
Summary
I tried to format this code:
pub(crate) const SETTINGS_SOURCE: crate::Parameters<crate::DefaultVariant> = crate::Parameters::<crate::DefaultVariant> { first: Some(1), last: Some(2) };
with max_width = 120.
Expected behavior
I expected the item to break after =, as the same item does when the name is one column longer:
pub(crate) const SETTINGS_SOURCEX: crate::Parameters<crate::DefaultVariant> =
crate::Parameters::<crate::DefaultVariant> {
first: Some(1),
last: Some(2),
};
Actual behavior
The first line stays at 121 columns, one past max_width, with the opening { as its last character, and the item is not broken after =:
pub(crate) const SETTINGS_SOURCE: crate::Parameters<crate::DefaultVariant> = crate::Parameters::<crate::DefaultVariant> {
first: Some(1),
last: Some(2),
};
With the name padded so that the first line would end in { at column 118, 119, 120, 121 and 122, the five items keep that first line at 118, 119, 120 and 121, and the one at 122 is broken after =. The same 121 columns with a call on the right, = crate::Settings::new(first, last), are broken after =.
Configuration
rustfmt cli options used:
$ rustfmt --edition 2024 --config-path rustfmt.toml input.rs
rustfmt.toml:
max_width = 120
Reproduction Steps
- Clone the reproducer gist,
git clone https://gist.github.com/YevheniiKotyrlo/2ae6769cd363cf59cf3c4bed2e9ff43f; it holdsinput.rs,rustfmt.tomlandrepro.sh.input.rsholds five items whose first line would end in{at 118 to 122 columns, and the call item above. - In the clone, run
bash repro.sh, which formatsinput.rswithrustfmt --edition 2024 --config-path rustfmt.tomland takes the rustfmt binary from its first argument, else theRUSTFMTenvironment variable, elserustfmtonPATH. - It prints the first line of each item with its width, then every line longer than
max_width, and ends with:
== the lines past 120
121 pub(crate) const SETTINGS_SOURCE: crate::Parameters<crate::DefaultVariant> = crate::Parameters::<crate::DefaultVariant> {
RESULT: the defect shows — a formatted line is past max_width
It exits 1 while a line is longer than max_width, and 0 after a fix, where the items at 118, 119 and 120 columns keep their first line and the two longest break after =.
Meta
rustfmt --version:
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
rustc --version: rustc 1.99.1 (58cf8f9c3 2026-10-13).
Reproduced on main 0acb4720feb76e209e7c61f0133efbe628a4641b as well, where rustfmt --version prints rustfmt 1.12.0-nightly (0acb4720fe 2026-11-10).
Host: Windows 11, x86_64-pc-windows-msvc.
- 主要语言
- Rust
- 星标
- 7.1k
- 派生
- 1.2k
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 20
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/rustfmt 的其他 Issue
-
A-config C-bug SO-print-config
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
A-Unicode C-bug P-low
难度 2/5 1-3 小时 新手友好度 70/100
rust-lang/rustfmt#7210 · 5 条评论 ·
维护者通常 1 天内回复
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
难度 2/5 1-3 小时 新手友好度 72/100
rust-lang/rustfmt#7173 · 1 条评论 ·
维护者通常 1 天内回复
-
A-comments C-bug only-with-option UO-indent_style
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Fix `first_line_width` to be tab-aware可能重新可做 关联的 PR 已关闭且未合并。 未关闭A-tabs A-whitespace C-bug SO-hard_tabs
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
查看 rust-lang/rustfmt 的全部 Issue
相似的 Issue
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)可能已有人在做 @mastel2 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
storytold/craft-anything#2538 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
compiler-explorer/compiler-explorer#9738 ·
维护者通常 2 天内回复
-
area: runtime enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
hffgzktbcc-blip/ounce-core#663 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
zellij-org/zellij#6026 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
tamatebako/tebako#1155 ·
维护者通常 1 天内回复