Improve comments about const panic handling

Co-authored-by: Ralf Jung <post@ralfj.de>
This commit is contained in:
Mara Bos 2021-07-10 18:39:25 +02:00
parent 4e6356188f
commit 0b8033ad8d
3 changed files with 7 additions and 2 deletions

View File

@ -31,6 +31,8 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx>],
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
// The list of functions we handle here must be in sync with
// `is_lang_panic_fn` in `transform/check_consts/mod.rs`.
let def_id = instance.def_id();
if Some(def_id) == self.tcx.lang_items().panic_fn()
|| Some(def_id) == self.tcx.lang_items().panic_str()

View File

@ -74,6 +74,9 @@ 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()

View File

@ -100,8 +100,8 @@ pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
if let Some(msg) = fmt.as_str() {
panic_str(msg);
} else {
// SAFETY: This is only evaluated at compile time, which handles this
// fine (in case it turns out this branch turns out to be reachable
// SAFETY: This is only evaluated at compile time, which reliably
// handles this UB (in case this branch turns out to be reachable
// somehow).
unsafe { crate::hint::unreachable_unchecked() };
}