mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 22:13:27 +00:00
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
This commit is contained in:
commit
eea5f8a9c4
21
tests/ui/panics/fmt-only-once.rs
Normal file
21
tests/ui/panics/fmt-only-once.rs
Normal file
@ -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)
|
||||
}
|
3
tests/ui/panics/fmt-only-once.run.stderr
Normal file
3
tests/ui/panics/fmt-only-once.run.stderr
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user