You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
f"{p}" refuses a struct that implements Display, though print(p) uses that impl #3005
pub type Point { x: i32, y: i32 }
impl Display for Point:
fn to_str() -> str: f"({self.x}, {self.y})"
fn main:
let p = Point { x: 1, y: 2 }
print(p) // (1, 2): print[T: Display]
print(f"{p:?}") // Point { x: 1, y: 2 }: Debug (derived here; an explicit impl Debug is honored, D61)
print(f"p = {p}") // error: struct type has no default display; use :? for debug
The default form refuses every struct before looking for a Display impl (check_display_interpolant in src/SemaCheck.w). That matches §15.4 ("Non-str expressions are converted to str via built-in formatting functions (no trait dispatch)") and §15.4.8 ("Using {some_struct} without :? is a
compile-time error"), so this is a question about the rule, not a report that the compiler breaks it.
It matters for library types: print(f"loss = {loss}") with an array, a decimal, a date or a dataframe
is the first line many users write, and today the only spellings are print(x) alone, {x:?} (the
Debug form) or {x.to_str()}. :? already dispatches to a user impl, so {} dispatching to Display
would follow the same path. Format specs ({x:.2}) could stay float-only.
Question. Should {x} use impl Display when the type has one (and keep the current error when it
doesn't)?
Checked on Linux x86_64 (WSL2) with release builds of main 14a720bd, 86dba3e9, a719f858 and 365c2008; main is now ecbc23b5, and nothing since 365c2008 touches f-string display.
Activity
#3016, #3032, #2946, #2976, #2949, #3051, #3005, #3001, #3017, #2521:…
ehartford commentedon Nov 7, 2026
Fixed in #3056 (merged as afbdbb1).