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

未关闭
#7,244 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
20

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/rustfmt 的其他 Issue

查看 rust-lang/rustfmt 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。