Shorten lifetime of panic temporaries in panic_fmt case

This commit is contained in:
David Tolnay 2022-11-07 13:23:16 -08:00
parent cbee2a1ec4
commit cb109a672d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 24 additions and 45 deletions

View File

@ -35,9 +35,11 @@ pub macro panic_2015 {
("{}", $arg:expr $(,)?) => (
$crate::panicking::panic_display(&$arg)
),
($fmt:expr, $($arg:tt)+) => (
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
),
($fmt:expr, $($arg:tt)+) => ({
// Semicolon to prevent temporaries inside the formatting machinery from
// being considered alive in the caller after the panic_fmt call.
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
}),
}
#[doc(hidden)]
@ -53,9 +55,11 @@ pub macro panic_2021 {
("{}", $arg:expr $(,)?) => (
$crate::panicking::panic_display(&$arg)
),
($($t:tt)+) => (
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
),
($($t:tt)+) => ({
// Semicolon to prevent temporaries inside the formatting machinery from
// being considered alive in the caller after the panic_fmt call.
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
}),
}
#[doc(hidden)]

View File

@ -26,7 +26,9 @@ pub macro panic_2015 {
$crate::rt::panic_display(&$arg)
}),
($fmt:expr, $($arg:tt)+) => ({
$crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
// Semicolon to prevent temporaries inside the formatting machinery from
// being considered alive in the caller after the panic_fmt call.
$crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
}),
}

View File

@ -1,4 +1,4 @@
// check-fail
// check-pass
// edition:2021
#![allow(unreachable_code)]
@ -15,5 +15,5 @@ async fn g() {
fn require_send(_: impl Send) {}
fn main() {
require_send(g()); //~ future cannot be sent between threads safely
require_send(g());
}

View File

@ -1,27 +0,0 @@
error: future cannot be sent between threads safely
--> $DIR/panic-temporaries.rs:18:18
|
LL | require_send(g());
| ^^^ future returned by `g` is not `Send`
|
= help: the trait `Sync` is not implemented for `core::fmt::Opaque`
note: future is not `Send` as this value is used across an await
--> $DIR/panic-temporaries.rs:12:20
|
LL | f(todo!("...")).await;
| ------------ ^^^^^^ await occurs here, with `$crate::format_args!($($arg)+)` maybe used later
| |
| has type `ArgumentV1<'_>` which is not `Send`
note: `$crate::format_args!($($arg)+)` is later dropped here
--> $DIR/panic-temporaries.rs:12:26
|
LL | f(todo!("...")).await;
| ^
note: required by a bound in `require_send`
--> $DIR/panic-temporaries.rs:15:25
|
LL | fn require_send(_: impl Send) {}
| ^^^^ required by this bound in `require_send`
error: aborting due to previous error

View File

@ -26,7 +26,7 @@ fn arbitrary_consuming_method_for_demonstration_purposes() {
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem as usize\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -42,7 +42,7 @@ fn addr_of() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: &elem\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -58,7 +58,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem == 1\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -71,7 +71,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem >= 1\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -84,7 +84,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem > 0\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -97,7 +97,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem < 3\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -110,7 +110,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem <= 3\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -123,7 +123,7 @@ fn binary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: elem != 3\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};
@ -139,7 +139,7 @@ fn unary() {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: *elem\nWith captures:\n elem = {0:?}\n",
__capture0))
__capture0));
}
}
};