rustfmt is off by one for comment length after a `where` keyword

Abierto
#7,260 0 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
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
tooling

Línea de trabajo

Reproduce first: build rustfmt from source and run it with wrap_comments = true and comment_width = 100 on the snippet from the report, confirming the 100-column comment gets wrapped after where. The wrapping logic lives in the comment rewriting code under src/comment.rs, with the available width passed in from the rewrite sites (including where-clause handling in src/items.rs); the off-by-one is likely in how the indentation offset is subtracted from comment_width. Add a fixture next to the existing comment tests under tests/ and run them to see the new behaviour; done means the comment is left untouched while unrelated wrapping still passes.

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

Descripción

A-comments A-where-clauses C-bug UO-comment_width UO-wrap_comments

Here is a Rust file with no line longer than 100 bytes, and one line equal to 100 bytes:

struct S<T>
where
    // This comment line is 100 columns long, yet rustfmt wraps it onto a second line: aaaaaaaaaaaaa
    T: Copy;

The comment shouldn't be changed by rustfmt, but it does change it:

> cat config.toml
wrap_comments = true
comment_width = 100

> rustfmt +nightly --version
rustfmt 1.12.0-nightly (bdf712ee87 2026-11-21)

> rustfmt +nightly --emit=stdout --config-path config.toml foo.rs
struct S<T>
where
    // This comment line is 100 columns long, yet rustfmt wraps it onto a second line:
    // aaaaaaaaaaaaa
    T: Copy;

(This is similar to #7258 and #7259, but I've filed it separately because I suspect it has a different root cause.)

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.