use std::fmt;
struct S;
impl fmt::Display for S {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("S");
Err(fmt::Error)
}
}
fn main() {
let a: String = format!("{}", S);
println!("{}", a);
}
…prints S and exits normally. (Same for ToString::to_string, they share the same implementation.)
I was very surprised as I thought this will panic (possibly after printing S, as this is hard to revert). I discovered this behavior while auditing Chrono’s formatting error semantics (#47) and I was unable to find a rationale for this. I did pinpoint the commit by @alexcrichton that introduced this change but that seems an unconscious change; can anyone confirm or deny my doubt?