From ad74480cb209eec4d09b12d5810c221d6b2f2d4c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 31 Mar 2020 16:53:00 +0200 Subject: [PATCH] avoid an unreachable fallback --- .../interpret/intrinsics/caller_location.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librustc_mir/interpret/intrinsics/caller_location.rs b/src/librustc_mir/interpret/intrinsics/caller_location.rs index e5307a8d65d2..f7e264b01d16 100644 --- a/src/librustc_mir/interpret/intrinsics/caller_location.rs +++ b/src/librustc_mir/interpret/intrinsics/caller_location.rs @@ -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.