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> { 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 /// 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 /// frame which is not `#[track_caller]`.
/// `None` is returned and the callsite of the function invocation itself should be used.
crate fn find_closest_untracked_caller_location(&self) -> Span { crate fn find_closest_untracked_caller_location(&self) -> Span {
self.stack self.stack
.iter() .iter()
.rev() .rev()
// Skip `#[track_caller]` frames. // Find first non-`#[track_caller]` frame.
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx)) .find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
// Find next frame with source info. // Assert that there is always such a frame.
.find_map(|frame| frame.current_source_info()) .unwrap()
.map(|si| si.span) .current_source_info()
// Fallback to current frame. That one has to have source_info as only // Assert that the frame we look at is actually executing code currently
// currently unwinding frames without cleanup do *not* have it -- and those // (`current_source_info` is None when we are unwinding and the frame does
// frames do not call this intrinsic. // not require cleanup).
.unwrap_or_else(|| self.frame().current_source_info().unwrap().span) .unwrap()
.span
} }
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers. /// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.