Skip to content

Commit ad74480

Browse files
committed
avoid an unreachable fallback
1 parent d8a0600 commit ad74480

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/librustc_mir/interpret/intrinsics/caller_location.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ use crate::interpret::{
1212

1313
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1414
/// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a
15-
/// frame which is not `#[track_caller]`. If the first frame found lacks `#[track_caller]`, then
16-
/// `None` is returned and the callsite of the function invocation itself should be used.
15+
/// frame which is not `#[track_caller]`.
1716
crate fn find_closest_untracked_caller_location(&self) -> Span {
1817
self.stack
1918
.iter()
2019
.rev()
21-
// Skip `#[track_caller]` frames.
22-
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
23-
// Find next frame with source info.
24-
.find_map(|frame| frame.current_source_info())
25-
.map(|si| si.span)
26-
// Fallback to current frame. That one has to have source_info as only
27-
// currently unwinding frames without cleanup do *not* have it -- and those
28-
// frames do not call this intrinsic.
29-
.unwrap_or_else(|| self.frame().current_source_info().unwrap().span)
20+
// Find first non-`#[track_caller]` frame.
21+
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
22+
// Assert that there is always such a frame.
23+
.unwrap()
24+
.current_source_info()
25+
// Assert that the frame we look at is actually executing code currently
26+
// (`current_source_info` is None when we are unwinding and the frame does
27+
// not require cleanup).
28+
.unwrap()
29+
.span
3030
}
3131

3232
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.

0 commit comments

Comments
 (0)