`struct_field_align_threshold` counts attributes in the alignment width of struct literal fields
Los mantenedores suelen responder en 1 día
@tkr-sh ya está trabajando en esto.
Desde el 24/10/2026.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 57/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- rust
- Área
- developer-experience
Línea de trabajo
Read the struct_field_align_threshold formatting logic and the context in the linked discussion for #7202; the issue provides Rust snippets showing how attributes affect alignment. Compare the current output with the proposed field-only alignment behavior and determine the expected treatment of multiline attributes. Done means the behavior is agreed upon and covered by formatting tests for the relevant cases.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hello,
This is a follow-up to #7202.
The PR was closed with the request to open an issue and discuss the expected behavior first, so here it is.
I noticed that when using the struct_field_align_threshold nightly option, there was a missbehavior where:
Self {
a: 1,
#[cfg(feature = "test")]
longer: 2,
}
was rewritten as:
Self {
a: 1,
#[cfg(feature = "test")]
longer: 2,
}
as if it was
#[cfg(feature = "test")] longer: 2,
Full context of why it occurs and why I think it's a bug here: https://github.com/rust-lang/rustfmt/pull/7202#issue-5951552048
Expected behavior
There is afaik 2 possible solutions, and one that seems better.
Option A: align to fields without care of attributes (imo the expected behavior)
Self {
a: 1,
#[cfg(feature = "test")]
longer: 2,
}
Option B: align to max(field.len(), attribute.len())
Self {
a: 1,
#[cfg(feature = "test")]
longer: 2,
}
Personally, this one seems a bit odd to me for 4 reasons:
- This is not following the name of the
rusfmtoption:struct_field_align_threshold(struct's field) - Let's say that we reorder the arguments order to have the cfg above with longer:
Self {
#[cfg(feature = "test")]
longer: 2,
a: 1,
}
I feel like this is really confusing compared to
Self {
#[cfg(feature = "test")]
longer: 2,
a: 1,
}
- This is not the behavior of a field definition:
// Current behavior of a struct / field definition.
struct Test {
a: u8,
#[cfg(feature = "test")]
longer: u8,
}
- If the goal is to avoid to have things "stick out", it will probably have the opposite effect:
Test {
a: String::from(
"aaaaaaaaaaaaaaa",
),
#[cfg(feature = "a")]
vvvvv: vec![],
}
vs
Test {
a: String::from(
"aaaaaaaaaaaaaaa",
),
#[cfg(feature = "a")]
vvvvv: vec![],
}
Which also has more chance to just be
Self {
a: String::from("aaaaaaaaaaaaaaa"),
#[cfg(feature = "a")]
vvvvv: vec![],
}
because it will usually be shorter.
Also remains the question of how to behave on multiline attribute with some parts sticking out:
Self {
a: String::from("aaaaaaaaaaaaaaa"),
#[cfg(
feature = "aaaaa"
)]
vvvvv: vec![],
}
which would be easily confusing, specially with wrapping:
Self {
a: String::from(
"aaaaaaaaaaaaaaa"
),
#[cfg(
feature = "aaaaa"
)]
vvvvv: vec![],
}
vs
Self {
a: String::from("aaaaaaaaaaaaaaa"),
#[cfg(
feature = "aaaaa"
)]
vvvvv: vec![],
}
and
Self {
a: String::from(
"aaaaaaaaaaaaaaa"
),
#[cfg(
feature = "aaaaa"
)]
vvvvv: vec![],
}
All of these elements combined + the current behavior of struct field definition, makes me lean towards option A.
- Lenguaje dominante
- Rust
- Estrellas
- 7.1k
- Forks
- 1.2k
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 20
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rustfmt
-
A-config C-bug SO-print-config
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
A-Unicode C-bug P-low
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
rust-lang/rustfmt#7210 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rust-lang/rustfmt#7173 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
A-comments C-bug only-with-option UO-indent_style
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Fix `first_line_width` to be tab-awareQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoA-tabs A-whitespace C-bug SO-hard_tabs
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rustfmt
Issues similares
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)Posiblemente ocupada @mastel2 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
storytold/craft-anything#2538 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
compiler-explorer/compiler-explorer#9738 ·
Los mantenedores suelen responder en 2 días
-
area: runtime enhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
hffgzktbcc-blip/ounce-core#663 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
zellij-org/zellij#6026 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
tamatebako/tebako#1155 ·
Los mantenedores suelen responder en 1 día