Skip to content

Commit 4745753

Browse files
committed
Shorten lifetime of panic temporaries in panic_fmt case
1 parent d044234 commit 4745753

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

core/src/panic.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ pub macro panic_2015 {
3535
("{}", $arg:expr $(,)?) => (
3636
$crate::panicking::panic_display(&$arg)
3737
),
38-
($fmt:expr, $($arg:tt)+) => (
39-
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
40-
),
38+
($fmt:expr, $($arg:tt)+) => ({
39+
// Semicolon to prevent temporaries inside the formatting machinery from
40+
// being considered alive in the caller after the panic_fmt call.
41+
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
42+
}),
4143
}
4244

4345
#[doc(hidden)]
@@ -53,9 +55,11 @@ pub macro panic_2021 {
5355
("{}", $arg:expr $(,)?) => (
5456
$crate::panicking::panic_display(&$arg)
5557
),
56-
($($t:tt)+) => (
57-
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
58-
),
58+
($($t:tt)+) => ({
59+
// Semicolon to prevent temporaries inside the formatting machinery from
60+
// being considered alive in the caller after the panic_fmt call.
61+
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
62+
}),
5963
}
6064

6165
#[doc(hidden)]

std/src/panic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub macro panic_2015 {
2626
$crate::rt::panic_display(&$arg)
2727
}),
2828
($fmt:expr, $($arg:tt)+) => ({
29-
$crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
29+
// Semicolon to prevent temporaries inside the formatting machinery from
30+
// being considered alive in the caller after the panic_fmt call.
31+
$crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
3032
}),
3133
}
3234

0 commit comments

Comments
 (0)