Improve comments about const panic handling
Co-authored-by: Ralf Jung <post@ralfj.de>
This commit is contained in:
parent
4e6356188f
commit
0b8033ad8d
3 changed files with 7 additions and 2 deletions
|
@ -31,6 +31,8 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
|
||||||
instance: ty::Instance<'tcx>,
|
instance: ty::Instance<'tcx>,
|
||||||
args: &[OpTy<'tcx>],
|
args: &[OpTy<'tcx>],
|
||||||
) -> InterpResult<'tcx, Option<ty::Instance<'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();
|
let def_id = instance.def_id();
|
||||||
if Some(def_id) == self.tcx.lang_items().panic_fn()
|
if Some(def_id) == self.tcx.lang_items().panic_fn()
|
||||||
|| Some(def_id) == self.tcx.lang_items().panic_str()
|
|| Some(def_id) == self.tcx.lang_items().panic_str()
|
||||||
|
|
|
@ -74,6 +74,9 @@ impl ConstCx<'mir, 'tcx> {
|
||||||
|
|
||||||
/// Returns `true` if this `DefId` points to one of the official `panic` lang items.
|
/// 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 {
|
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_fn()
|
||||||
|| Some(def_id) == tcx.lang_items().panic_str()
|
|| Some(def_id) == tcx.lang_items().panic_str()
|
||||||
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
|
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
|
||||||
|
|
|
@ -100,8 +100,8 @@ pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
||||||
if let Some(msg) = fmt.as_str() {
|
if let Some(msg) = fmt.as_str() {
|
||||||
panic_str(msg);
|
panic_str(msg);
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: This is only evaluated at compile time, which handles this
|
// SAFETY: This is only evaluated at compile time, which reliably
|
||||||
// fine (in case it turns out this branch turns out to be reachable
|
// handles this UB (in case this branch turns out to be reachable
|
||||||
// somehow).
|
// somehow).
|
||||||
unsafe { crate::hint::unreachable_unchecked() };
|
unsafe { crate::hint::unreachable_unchecked() };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue