forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#110721 - lukas-code:panic-fmt, r=Amanieu
format panic message only once For `panic!` and friends, the `std` panic runtime will always set the `.payload()` of `PanicInfo` to the formatted string. The linked issues show that formatting the message twice can cause problems, so we simply print the already formatted message instead of formatting it again. We can't remove the preformatted payload, because it can be observed by custom panic hooks. fixes rust-lang#110717 fixes rust-itertools/itertools#694 cc ``@Amanieu`` who broke this in rust-lang#109507
- Loading branch information
Showing
3 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |