Skip to content

Commit eea5f8a

Browse files
authored
Rollup merge of rust-lang#110721 - lukas-code:panic-fmt, r=Amanieu
format panic message only once Formatting the panic message multiple times can cause problems for some real-world crates, so here's a test to ensure that we don't do that. This was regressed in rust-lang#109507 and reverted in rust-lang#110782. fixes rust-lang#110717 fixes rust-itertools/itertools#694
2 parents 085fbe9 + cd398a6 commit eea5f8a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/ui/panics/fmt-only-once.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-fail
2+
// check-run-results
3+
// exec-env:RUST_BACKTRACE=0
4+
5+
// Test that we format the panic message only once.
6+
// Regression test for https://github.com/rust-lang/rust/issues/110717
7+
8+
use std::fmt;
9+
10+
struct PrintOnFmt;
11+
12+
impl fmt::Display for PrintOnFmt {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
eprintln!("fmt");
15+
f.write_str("PrintOnFmt")
16+
}
17+
}
18+
19+
fn main() {
20+
panic!("{}", PrintOnFmt)
21+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fmt
2+
thread 'main' panicked at 'PrintOnFmt', $DIR/fmt-only-once.rs:20:5
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)