println/format strings only support a bare {} (no float precision, width or radix)

Abierto
#929 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
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Start by locating the parser and formatter implementation for println format strings, then trace how placeholders are parsed and how f64 values are rendered. The issue gives a reproducer using {:.2} and describes desired precision, width, padding, alignment, and integer radix support. Add the supported formatting behavior and tests for those cases; done when the reproducer formats the float as requested and unsupported syntax is handled consistently.

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

Descripción

Feature request: println / format strings accept only a bare {}. There is no way to control the number of fraction digits of a float, width or padding.

Repro

fun main() {
    var c: f64 = 0.1;
    println("{:.2}", c);
}
error[E2001]: failed to parse Wave source: unsupported format placeholder `{:.2}`

The error is clear, so this is not a diagnostics problem. The gap is that {} on an f64 always prints six fraction digits (0.100000), so a program that wants 0.10, or the full precision of a double, has to format the number by hand.

I hit this while writing a JSON library in Wave: I had to implement shortest round-trip and fixed-precision double formatting myself just to print a number the way I wanted.

Suggestion

Support at least {:.N} (precision) for floats, and ideally width/fill/alignment ({:5}, {:>8}, {:08}) and an integer radix ({:x}), or document that formatting is expected to be done in library code.

Version

wavec 0.2.1-pre-beta (LLVM 21.1.8), Ubuntu 26.04, x86_64.

Lenguaje dominante
Rust
Estrellas
56
Forks
21
Merge medio
23 h 20 min
PR fusionados (30 d)
45

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 wavefnd/Wave

Todos los issues de wavefnd/Wave

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.