1
Fork 0

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

@ -276,13 +276,16 @@ language_item_table! {
// is required to define it somewhere. Additionally, there are restrictions on crates that use
// a weak lang item, but do not have it defined.
Panic, sym::panic, panic_fn, Target::Fn;
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn;
PanicStr, sym::panic_str, panic_str, Target::Fn;
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn;
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn;
PanicInfo, sym::panic_info, panic_info, Target::Struct;
PanicLocation, sym::panic_location, panic_location, Target::Struct;
PanicImpl, sym::panic_impl, panic_impl, Target::Fn;
/// libstd panic entry point. Necessary for const eval to be able to catch it
BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn;
BeginPanicFmt, sym::begin_panic_fmt, begin_panic_fmt, Target::Fn;
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn;
BoxFree, sym::box_free, box_free_fn, Target::Fn;