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

Aperta
#929 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

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.

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

Descrizione

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.

Lingua principale
Rust
Stelle
56
Fork
21
Merge medio
23h 20m
PR unite (30g)
45

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

Tutte le issue di wavefnd/Wave

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.