comment_width should be independent of indent
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
- 45/100
Hướng nghiên cứu
The issue asks that comment_width be measured without the indentation of the comment, and it points to #6802 as the change that made it indent-aware. Start by reading that pull request to see where the indent is subtracted, then reproduce the two examples with comment_width = 40 and wrap_comments = true. Done means the indented comment wraps at 40 characters of its own text, the empty trailing // line is not added, and the existing wrap_comments tests still pass. Because the maintainers may need to agree on the design first, check for a decision before you start.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The global line length limit in rustfmt is configured with max_width. Outside of that, certain types of expression can be configured with their own widths, so that those expressions can have their own custom aesthetics in terms of horizontal vs vertical layout.
For example, array_width limits the length of array literals independently of max_width. comment_width is another of these properties, which limits comments to 80 characters by default. I'm assuming this is to aid users in keeping their place when reading dense blocks of text.
There was an issue (#6801) with wrap_comments not properly enforcing comment_width when things like bulleted lists were involved. It looks like the fix (#6802) involved making comment_width indent-aware; however, I think this is against the spirit of how custom *_width properties should work. All other *_width properties are not applied with indent taken into account. The properties themselves are about the length of the expression itself, independent of indentation.
It would be weird for array_width = 60 to format [1, 2, 3, 4] as a multi-line literal because the line is indented 52 characters. Similarly, it is weird for comment_width to be applied with indents taken into account.
For example:
Expected behavior
// comment_width = 40
// wrap_comments = true
// This is a comment where there is no
// leading indent. Wrapping happens at
// the 40th column.
fn function() {
for y in 0..height {
for x in 0..width {
if foo {
if bar {
if baz {
if should_frobnicate {
// This is a comment where there is a
// leading indent. Wrapping should
// happen once the comment exceeds 40
// characters.
}
}
}
}
}
}
}
Actual behavior
// comment_width = 40
// wrap_comments = true
// This is a comment where there is no
// leading indent. Wrapping happens at
// the 40th column.
fn function() {
for y in 0..height {
for x in 0..width {
if foo {
if bar {
if baz {
if should_frobnicate {
// This is a
// comment where
// there is a
// leading indent.
// Wrapping should
// happen once
// the comment
// exceeds 40
// characters.
}
}
}
}
}
}
}
Note: The indented comment reaches column 46, so even the indent-aware wrapping exceeds comment_width.
Note: When the comment starts on a single line, the first format pass also adds an empty // line at the end of the indented comment block. It doesn’t come back once removed.
Configuration
This happens with wrap_comments = true, although the examples above also use comment_width = 40 so shallower nesting can be used to demonstrate the issue.
Meta
rustfmt --version:
rustfmt 1.11.0-nightly (92b5b8c87c 2026-10-29)
- 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