Skip to content

Commit 962459e

Browse files
committed
io::Write::write_fmt: panic if the formatter fails when the stream does not fail
1 parent ef15976 commit 962459e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

library/alloc/src/fmt.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ pub fn format(args: Arguments<'_>) -> string::String {
630630
fn format_inner(args: Arguments<'_>) -> string::String {
631631
let capacity = args.estimated_capacity();
632632
let mut output = string::String::with_capacity(capacity);
633-
output.write_fmt(args).expect("a formatting trait implementation returned an error");
633+
output
634+
.write_fmt(args)
635+
.expect("a formatting trait implementation returned an error when the underlying stream did not");
634636
output
635637
}
636638

library/std/src/io/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,11 @@ pub trait Write {
18391839
if output.error.is_err() {
18401840
output.error
18411841
} else {
1842-
Err(error::const_io_error!(ErrorKind::Uncategorized, "formatter error"))
1842+
// This shouldn't happen: the underlying stream did not error, but somehow
1843+
// the formatter still errored?
1844+
panic!(
1845+
"a formatting trait implementation returned an error when the underlying stream did not"
1846+
);
18431847
}
18441848
}
18451849
}

0 commit comments

Comments
 (0)