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

Abierto
#7,244 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Rust
Estrellas
7.1k
Forks
1.2k
Merge medio
1 d 4 h
PR fusionados (30 d)
20

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rustfmt

Todos los issues de rust-lang/rustfmt

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.