about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-29 07:12:07 +0000
committerbors <bors@rust-lang.org>2021-07-29 07:12:07 +0000
commit6e0a8bf7901a3fe2e073b1e702e80f58b76d5087 (patch)
treebd9b79e97e2d2204a5a1c2e22b9459811cc59809 /compiler/rustc_mir/src/transform
parent581b1664c92f78f3d15181c78a16480987256ecb (diff)
parent312bf8e0b8122fd681adf28f65e88f8d15f7a34c (diff)
downloadrust-6e0a8bf7901a3fe2e073b1e702e80f58b76d5087.tar.gz
rust-6e0a8bf7901a3fe2e073b1e702e80f58b76d5087.zip
Auto merge of #86998 - m-ou-se:const-panic-fmt-as-str, r=oli-obk
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.

r? `@RalfJung`
Diffstat (limited to 'compiler/rustc_mir/src/transform')
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/mod.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/check_consts/mod.rs b/compiler/rustc_mir/src/transform/check_consts/mod.rs
index 0ca086d74db..7e22ed22db4 100644
--- a/compiler/rustc_mir/src/transform/check_consts/mod.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/mod.rs
@@ -74,9 +74,14 @@ impl ConstCx<'mir, 'tcx> {
 
 /// Returns `true` if this `DefId` points to one of the official `panic` lang items.
 pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
+    // We can allow calls to these functions because `hook_panic_fn` in
+    // `const_eval/machine.rs` ensures the calls are handled specially.
+    // Keep in sync with what that function handles!
     Some(def_id) == tcx.lang_items().panic_fn()
         || Some(def_id) == tcx.lang_items().panic_str()
         || Some(def_id) == tcx.lang_items().begin_panic_fn()
+        || Some(def_id) == tcx.lang_items().panic_fmt()
+        || Some(def_id) == tcx.lang_items().begin_panic_fmt()
 }
 
 pub fn rustc_allow_const_fn_unstable(