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

Aperta
#7,244 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Rust
Stelle
7.1k
Fork
1.2k
Merge medio
1g 4h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rustfmt

Tutte le issue di rust-lang/rustfmt

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.