Make const panic!("..") work in Rust 2021.

During const eval, this replaces calls to core::panicking::panic_fmt and
std::panicking::being_panic_fmt with a call to a new const fn:
core::panicking::const_panic_fmt. That function uses
fmt::Arguments::as_str() to get the str and calls panic_str with that
instead.

panic!() invocations with formatting arguments are still not accepted,
as the creation of such a fmt::Arguments cannot be done in constant
functions right now.
This commit is contained in:
Mara Bos 2021-07-06 12:38:26 +00:00
parent eba3228b2a
commit f827d3e285
8 changed files with 53 additions and 11 deletions

View file

@ -323,6 +323,7 @@ symbols! {
await_macro,
bang,
begin_panic,
begin_panic_fmt,
bench,
bin,
bind_by_move_pattern_guards,
@ -420,6 +421,7 @@ symbols! {
const_loop,
const_mut_refs,
const_panic,
const_panic_fmt,
const_precise_live_drops,
const_ptr,
const_raw_ptr_deref,
@ -586,6 +588,7 @@ symbols! {
fmaf32,
fmaf64,
fmt,
fmt_as_str,
fmt_internals,
fmul_fast,
fn_align,
@ -881,6 +884,7 @@ symbols! {
panic_2021,
panic_abort,
panic_bounds_check,
panic_fmt,
panic_handler,
panic_impl,
panic_implementation,