1
Fork 0

avoid an unreachable fallback

This commit is contained in:
Ralf Jung 2020-03-31 16:53:00 +02:00
parent d8a0600f56
commit ad74480cb2

View file

@ -12,21 +12,21 @@ use crate::interpret::{
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a
/// frame which is not `#[track_caller]`. If the first frame found lacks `#[track_caller]`, then
/// `None` is returned and the callsite of the function invocation itself should be used.
/// frame which is not `#[track_caller]`.
crate fn find_closest_untracked_caller_location(&self) -> Span {
self.stack
.iter()
.rev()
// Skip `#[track_caller]` frames.
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
// Find next frame with source info.
.find_map(|frame| frame.current_source_info())
.map(|si| si.span)
// Fallback to current frame. That one has to have source_info as only
// currently unwinding frames without cleanup do *not* have it -- and those
// frames do not call this intrinsic.
.unwrap_or_else(|| self.frame().current_source_info().unwrap().span)
// Find first non-`#[track_caller]` frame.
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
// Assert that there is always such a frame.
.unwrap()
.current_source_info()
// Assert that the frame we look at is actually executing code currently
// (`current_source_info` is None when we are unwinding and the frame does
// not require cleanup).
.unwrap()
.span
}
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.