`/* ... */` comments at the end of a block can be rewritten to `/* ... //` with no terminating `*/`

Đang mở
#7,244 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Nửa ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
devtools

Hướng nghiên cứu

Start from the separate comment handling path in close_block, which the report says was not covered by PR 7217, and reproduce with the snippet using wrap_comments=true and normalize_comments=true. Check how a trailing /* ... */ block comment is rewritten to // lines and make sure the closing */ is never dropped. Done when the snippet formats to the expected output and the output compiles.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A-comments C-bug UO-normalize_comments UO-wrap_comments

With wrap_comments or normalize_comments, a /* ... */ trailing block comment at the end of a block can be rewritten to /* ... // without a closing */, resulting in invalid code that doesn't compile. This is the same issue as https://github.com/rust-lang/rustfmt/issues/6339, but there's a separate comment handling path in close_block that didn't get fixed in https://github.com/rust-lang/rustfmt/pull/7217.

Note that this only occurs on SE 2024 and later. The issue won't happen on SE 2015.

Summary

I tried to format this code:

fn block_comment() {
    let x = 1; /* first
                * second
                */
}

I tried to format with wrap_comments: true and normalize_comments: true.

Expected behavior
fn block_comment() {
    let x = 1; // first
    // second
}
Actual behavior
fn block_comment() {
    let x = 1; /* first
    // second
}

Configuration

Tested against main commit 0acb4720feb76e209e7c61f0133efbe628a4641b.

rustfmt cli options used (if applicable):

cargo run --bin rustfmt -- --style-edition 2024 --config wrap_comments=true  test.rs
cargo run --bin rustfmt -- --style-edition 2024 --config normalize_comments=true  test.rs
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rustfmt

Tất cả issue của rust-lang/rustfmt

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.