diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-04-28 10:51:59 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-28 10:51:59 +0900 |
| commit | eea5f8a9c43c0996a01b53c2f1720f8712ba81df (patch) | |
| tree | d894f86e1bbb822336419f6395104b96f9085715 | |
| parent | 085fbe90984bce639afdd1c2153a092a1adcadd4 (diff) | |
| parent | cd398a6de9a177137b493f2355a3b4db4ab8d02a (diff) | |
| download | rust-eea5f8a9c43c0996a01b53c2f1720f8712ba81df.tar.gz rust-eea5f8a9c43c0996a01b53c2f1720f8712ba81df.zip | |
Rollup merge of #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 https://github.com/rust-lang/rust/pull/109507 and reverted in https://github.com/rust-lang/rust/pull/110782. fixes https://github.com/rust-lang/rust/issues/110717 fixes https://github.com/rust-itertools/itertools/issues/694
| -rw-r--r-- | tests/ui/panics/fmt-only-once.rs | 21 | ||||
| -rw-r--r-- | tests/ui/panics/fmt-only-once.run.stderr | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/panics/fmt-only-once.rs b/tests/ui/panics/fmt-only-once.rs new file mode 100644 index 00000000000..6211bf961b3 --- /dev/null +++ b/tests/ui/panics/fmt-only-once.rs @@ -0,0 +1,21 @@ +// run-fail +// check-run-results +// exec-env:RUST_BACKTRACE=0 + +// Test that we format the panic message only once. +// Regression test for https://github.com/rust-lang/rust/issues/110717 + +use std::fmt; + +struct PrintOnFmt; + +impl fmt::Display for PrintOnFmt { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + eprintln!("fmt"); + f.write_str("PrintOnFmt") + } +} + +fn main() { + panic!("{}", PrintOnFmt) +} diff --git a/tests/ui/panics/fmt-only-once.run.stderr b/tests/ui/panics/fmt-only-once.run.stderr new file mode 100644 index 00000000000..39bd06881ad --- /dev/null +++ b/tests/ui/panics/fmt-only-once.run.stderr @@ -0,0 +1,3 @@ +fmt +thread 'main' panicked at 'PrintOnFmt', $DIR/fmt-only-once.rs:20:5 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
