Skip to content

Commit b19bf06

Browse files
committed
Auto merge of rust-lang#129491 - StackOverflowExcept1on:master, r=m-ou-se
Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage` Resolves rust-lang#129330 For some reason after rust-lang#115974 and rust-lang#126732 optimizations applied to panic handler became worse and compiler stopped removing panic locations if they are not used in the panic message. This PR fixes that and maybe we can merge it into beta before rust 1.81 is released. Note: optimization only works with `lto = "fat"`. r? libs-api
2 parents 37eb770 + 4bc6b1f commit b19bf06

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

core/src/panic/panic_info.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::panic::Location;
1212
#[stable(feature = "panic_hooks", since = "1.10.0")]
1313
#[derive(Debug)]
1414
pub struct PanicInfo<'a> {
15-
message: fmt::Arguments<'a>,
15+
message: &'a fmt::Arguments<'a>,
1616
location: &'a Location<'a>,
1717
can_unwind: bool,
1818
force_no_backtrace: bool,
@@ -26,13 +26,13 @@ pub struct PanicInfo<'a> {
2626
/// See [`PanicInfo::message`].
2727
#[stable(feature = "panic_info_message", since = "1.81.0")]
2828
pub struct PanicMessage<'a> {
29-
message: fmt::Arguments<'a>,
29+
message: &'a fmt::Arguments<'a>,
3030
}
3131

3232
impl<'a> PanicInfo<'a> {
3333
#[inline]
3434
pub(crate) fn new(
35-
message: fmt::Arguments<'a>,
35+
message: &'a fmt::Arguments<'a>,
3636
location: &'a Location<'a>,
3737
can_unwind: bool,
3838
force_no_backtrace: bool,
@@ -146,7 +146,7 @@ impl Display for PanicInfo<'_> {
146146
formatter.write_str("panicked at ")?;
147147
self.location.fmt(formatter)?;
148148
formatter.write_str(":\n")?;
149-
formatter.write_fmt(self.message)?;
149+
formatter.write_fmt(*self.message)?;
150150
Ok(())
151151
}
152152
}
@@ -177,14 +177,14 @@ impl<'a> PanicMessage<'a> {
177177
impl Display for PanicMessage<'_> {
178178
#[inline]
179179
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
180-
formatter.write_fmt(self.message)
180+
formatter.write_fmt(*self.message)
181181
}
182182
}
183183

184184
#[stable(feature = "panic_info_message", since = "1.81.0")]
185185
impl fmt::Debug for PanicMessage<'_> {
186186
#[inline]
187187
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
188-
formatter.write_fmt(self.message)
188+
formatter.write_fmt(*self.message)
189189
}
190190
}

core/src/panicking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
6464
}
6565

6666
let pi = PanicInfo::new(
67-
fmt,
67+
&fmt,
6868
Location::caller(),
6969
/* can_unwind */ true,
7070
/* force_no_backtrace */ false,
@@ -102,7 +102,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
102102

103103
// PanicInfo with the `can_unwind` flag set to false forces an abort.
104104
let pi = PanicInfo::new(
105-
fmt,
105+
&fmt,
106106
Location::caller(),
107107
/* can_unwind */ false,
108108
force_no_backtrace,

0 commit comments

Comments
 (0)