Skip to content

Commit b46c7d1

Browse files
committed
Auto merge of rust-lang#111590 - dtolnay:panictemporaries, r=bjorn3
Shorten even more panic temporary lifetimes Followup to rust-lang#104134. As pointed out by `@bjorn3` in rust-lang#104134 (review), there are other cases in the panic macros which would also benefit from dropping their non-Send temporaries as soon as possible, avoiding pointlessly holding them across an await point. For the tests added in this PR, here are the failures you get today on master without the macro changes in this PR: <details> <summary>tests/ui/macros/panic-temporaries-2018.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:53:18 | LL | require_send(panic_str()); | ^^^^^^^^^^^ future returned by `panic_str` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:40:36 | LL | f(panic!((NOT_SEND, "...").1)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 5 previous errors ``` </details> <details> <summary>tests/ui/macros/panic-temporaries.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 2 previous errors ``` </details> r? bjorn3
2 parents 7b63d1b + 9904268 commit b46c7d1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

core/src/panic.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ pub macro panic_2015 {
2828
$crate::panicking::panic($msg)
2929
),
3030
// Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
31-
($msg:expr $(,)?) => (
32-
$crate::panicking::panic_str($msg)
33-
),
31+
($msg:expr $(,)?) => ({
32+
$crate::panicking::panic_str($msg);
33+
}),
3434
// Special-case the single-argument case for const_panic.
35-
("{}", $arg:expr $(,)?) => (
36-
$crate::panicking::panic_display(&$arg)
37-
),
35+
("{}", $arg:expr $(,)?) => ({
36+
$crate::panicking::panic_display(&$arg);
37+
}),
3838
($fmt:expr, $($arg:tt)+) => ({
3939
// Semicolon to prevent temporaries inside the formatting machinery from
4040
// being considered alive in the caller after the panic_fmt call.
@@ -52,9 +52,9 @@ pub macro panic_2021 {
5252
$crate::panicking::panic("explicit panic")
5353
),
5454
// Special-case the single-argument case for const_panic.
55-
("{}", $arg:expr $(,)?) => (
56-
$crate::panicking::panic_display(&$arg)
57-
),
55+
("{}", $arg:expr $(,)?) => ({
56+
$crate::panicking::panic_display(&$arg);
57+
}),
5858
($($t:tt)+) => ({
5959
// Semicolon to prevent temporaries inside the formatting machinery from
6060
// being considered alive in the caller after the panic_fmt call.
@@ -73,9 +73,9 @@ pub macro unreachable_2015 {
7373
),
7474
// Use of `unreachable_display` for non_fmt_panic lint.
7575
// NOTE: the message ("internal error ...") is embedded directly in unreachable_display
76-
($msg:expr $(,)?) => (
77-
$crate::panicking::unreachable_display(&$msg)
78-
),
76+
($msg:expr $(,)?) => ({
77+
$crate::panicking::unreachable_display(&$msg);
78+
}),
7979
($fmt:expr, $($arg:tt)*) => (
8080
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
8181
),

std/src/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ pub macro panic_2015 {
1919
$crate::rt::begin_panic("explicit panic")
2020
}),
2121
($msg:expr $(,)?) => ({
22-
$crate::rt::begin_panic($msg)
22+
$crate::rt::begin_panic($msg);
2323
}),
2424
// Special-case the single-argument case for const_panic.
2525
("{}", $arg:expr $(,)?) => ({
26-
$crate::rt::panic_display(&$arg)
26+
$crate::rt::panic_display(&$arg);
2727
}),
2828
($fmt:expr, $($arg:tt)+) => ({
2929
// Semicolon to prevent temporaries inside the formatting machinery from

0 commit comments

Comments
 (0)