`max_width` is exceeded by one column when a struct literal's `{` ends the first line
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 7.1k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/rustfmt
-
A-config C-bug SO-print-config
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-Unicode C-bug P-low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
rust-lang/rustfmt#7210 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rust-lang/rustfmt#7173 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A-comments C-bug only-with-option UO-indent_style
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Fix `first_line_width` to be tab-awareCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởA-tabs A-whitespace C-bug SO-hard_tabs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/rustfmt
Issue tương tự
-
fix: production-image scan fails on base-image CVEs (libzstd, libssl)Có thể đã có người làm @Kravalg đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
VilnaCRM-Org/notification-service#41 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)Có thể đã có người làm @mastel2 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
storytold/craft-anything#2538 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
compiler-explorer/compiler-explorer#9738 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area: runtime enhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
hffgzktbcc-blip/ounce-core#663 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
zellij-org/zellij#6026 ·
Maintainer thường phản hồi trong vòng 1 ngày