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

オープン
#7,244 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
devtools

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Rust
スター
7.1k
フォーク
1.2k
平均マージ
1日 4時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rustfmt のほかの issue

rust-lang/rustfmt の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。