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

Đang mở
#929 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
56
Fork
21
Merge trung bình
23 giờ 20 phút
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wavefnd/Wave

Tất cả issue của wavefnd/Wave

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.