Skip to content

Commit 7777bdd

Browse files
committed
Patch core
1 parent 0f2e162 commit 7777bdd

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

library/core/src/panic.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
1717

1818
#[doc(hidden)]
1919
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
20-
#[allow_internal_unstable(panic_internals, const_format_args)]
20+
#[allow_internal_unstable(panic_internals, const_format_args, never_type, stmt_expr_attributes)]
2121
#[rustc_diagnostic_item = "core_panic_2015_macro"]
2222
#[rustc_macro_transparency = "semitransparent"]
2323
pub macro panic_2015 {
@@ -28,23 +28,26 @@ 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 $(,)?) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
32+
let _never = $crate::panicking::panic_str($msg);
33+
_never
34+
})),
3435
// Special-case the single-argument case for const_panic.
35-
("{}", $arg:expr $(,)?) => ({
36-
$crate::panicking::panic_display(&$arg);
37-
}),
38-
($fmt:expr, $($arg:tt)+) => ({
36+
("{}", $arg:expr $(,)?) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
37+
let _never = $crate::panicking::panic_display(&$arg);
38+
_never
39+
})),
40+
($fmt:expr, $($arg:tt)+) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
3941
// Semicolon to prevent temporaries inside the formatting machinery from
4042
// being considered alive in the caller after the panic_fmt call.
41-
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
42-
}),
43+
let _never = $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
44+
_never
45+
})),
4346
}
4447

4548
#[doc(hidden)]
4649
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
47-
#[allow_internal_unstable(panic_internals, const_format_args)]
50+
#[allow_internal_unstable(panic_internals, const_format_args, never_type, stmt_expr_attributes)]
4851
#[rustc_diagnostic_item = "core_panic_2021_macro"]
4952
#[rustc_macro_transparency = "semitransparent"]
5053
#[cfg(feature = "panic_immediate_abort")]
@@ -53,14 +56,16 @@ pub macro panic_2021 {
5356
$crate::panicking::panic("explicit panic")
5457
),
5558
// Special-case the single-argument case for const_panic.
56-
("{}", $arg:expr $(,)?) => ({
57-
$crate::panicking::panic_display(&$arg);
58-
}),
59-
($($t:tt)+) => ({
59+
("{}", $arg:expr $(,)?) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
60+
let _never = $crate::panicking::panic_display(&$arg);
61+
_never
62+
})),
63+
($($t:tt)+) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
6064
// Semicolon to prevent temporaries inside the formatting machinery from
6165
// being considered alive in the caller after the panic_fmt call.
62-
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
63-
}),
66+
let _never = $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
67+
_never
68+
})),
6469
}
6570

6671
#[doc(hidden)]
@@ -71,13 +76,15 @@ pub macro panic_2021 {
7176
const_dispatch,
7277
const_eval_select,
7378
const_format_args,
74-
rustc_attrs
79+
rustc_attrs,
80+
never_type,
81+
stmt_expr_attributes
7582
)]
7683
#[rustc_diagnostic_item = "core_panic_2021_macro"]
7784
#[rustc_macro_transparency = "semitransparent"]
7885
#[cfg(not(feature = "panic_immediate_abort"))]
7986
pub macro panic_2021 {
80-
() => ({
87+
() => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
8188
// Create a function so that the argument for `track_caller`
8289
// can be moved inside if possible.
8390
#[cold]
@@ -86,10 +93,11 @@ pub macro panic_2021 {
8693
const fn panic_cold_explicit() -> ! {
8794
$crate::panicking::panic_explicit()
8895
}
89-
panic_cold_explicit();
90-
}),
96+
let _never = panic_cold_explicit();
97+
_never
98+
})),
9199
// Special-case the single-argument case for const_panic.
92-
("{}", $arg:expr $(,)?) => ({
100+
("{}", $arg:expr $(,)?) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
93101
#[cold]
94102
#[track_caller]
95103
#[inline(never)]
@@ -98,18 +106,20 @@ pub macro panic_2021 {
98106
const fn panic_cold_display<T: $crate::fmt::Display>(arg: &T) -> ! {
99107
$crate::panicking::panic_display(arg)
100108
}
101-
panic_cold_display(&$arg);
102-
}),
103-
($($t:tt)+) => ({
109+
let _never = panic_cold_display(&$arg);
110+
_never
111+
})),
112+
($($t:tt)+) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
104113
// Semicolon to prevent temporaries inside the formatting machinery from
105114
// being considered alive in the caller after the panic_fmt call.
106-
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
107-
}),
115+
let _never = $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
116+
_never
117+
})),
108118
}
109119

110120
#[doc(hidden)]
111121
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
112-
#[allow_internal_unstable(panic_internals)]
122+
#[allow_internal_unstable(panic_internals, never_type, stmt_expr_attributes)]
113123
#[rustc_diagnostic_item = "unreachable_2015_macro"]
114124
#[rustc_macro_transparency = "semitransparent"]
115125
pub macro unreachable_2015 {
@@ -118,9 +128,10 @@ pub macro unreachable_2015 {
118128
),
119129
// Use of `unreachable_display` for non_fmt_panic lint.
120130
// NOTE: the message ("internal error ...") is embedded directly in unreachable_display
121-
($msg:expr $(,)?) => ({
122-
$crate::panicking::unreachable_display(&$msg);
123-
}),
131+
($msg:expr $(,)?) => (#[allow(unreachable_code)] $crate::convert::identity::<!>({
132+
let _never = $crate::panicking::unreachable_display(&$msg);
133+
_never
134+
})),
124135
($fmt:expr, $($arg:tt)*) => (
125136
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
126137
),

library/core/src/panicking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
264264
// SAFETY: This is only evaluated at compile time, which reliably
265265
// handles this UB (in case this branch turns out to be reachable
266266
// somehow).
267-
unsafe { crate::hint::unreachable_unchecked() };
267+
unsafe { crate::hint::unreachable_unchecked() }
268268
}
269269
}
270270

0 commit comments

Comments
 (0)