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
use std::fmt;use std::io::{self,Write};structFoo;impl fmt::DisplayforFoo{fnfmt(&self, _:&mut fmt::Formatter) -> fmt::Result{Err(fmt::Error)}}fnmain(){write!(io::stdout(),"{} {} {}",1,Foo,"bar").unwrap();}
the expected result, as far as I can tell, is a panic. Instead it just prints 1, apparently terminating at the formatting error of Foo but otherwise suppressing the error and returning Ok from write!.
(I encountered this behavior in the wild on current 1.6 stable. The above is a minimal example that reproduces it).
If this is intended, I find it extremely surprising. For one, this would mean there is no reliable way to distinguish formatting errors (Err returned from Display::fmt) from Display implementations that simply return an empty string in the simple format!("{}", ...) cases.
But if that's the intended behavior, then this probably qualifies as a documentation bug or omission, because there is no explanation what is the effect of returning Err from Display:::fmt.
The text was updated successfully, but these errors were encountered:
Hm I thought we already had an issue for this, but I can't seem to find it now. The problem here is that we assume that fmt::Error is never "just generated", but rather it always originates from the underlying writer returning an error. This is probably a relatively easy fix in the code.
…xcrichton
Make sure formatter errors are emitted by the default Write::write_fmt
Previously, if an error was returned from the formatter that did not
originate in an underlying writer error, Write::write_fmt would return
successfully even if the formatting did not complete (was interrupted by
an `fmt::Error` return).
Now we choose to emit an io::Error with kind Other for formatter errors.
Since this may reveal error returns from `write!()` and similar that
previously passed silently, it's a kind of a [breaking-change].
Fixesrust-lang#31879
I've encountered a surprising and undocumented behavior of
Display::fmt
, which I was advised on #rust to file an issue about.Given the code (http://is.gd/iRjVCG):
the expected result, as far as I can tell, is a panic. Instead it just prints
1
, apparently terminating at the formatting error ofFoo
but otherwise suppressing the error and returningOk
fromwrite!
.(I encountered this behavior in the wild on current 1.6 stable. The above is a minimal example that reproduces it).
If this is intended, I find it extremely surprising. For one, this would mean there is no reliable way to distinguish formatting errors (
Err
returned fromDisplay::fmt
) fromDisplay
implementations that simply return an empty string in the simpleformat!("{}", ...)
cases.But if that's the intended behavior, then this probably qualifies as a documentation bug or omission, because there is no explanation what is the effect of returning
Err
fromDisplay:::fmt
.The text was updated successfully, but these errors were encountered: