@@ -939,6 +939,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
939
939
/// Get the current span in the topmost function which is workspace-local and not
940
940
/// `#[track_caller]`.
941
941
/// This function is backed by a cache, and can be assumed to be very fast.
942
+ /// It will work even when the stack is empty.
942
943
pub fn current_span ( & self ) -> Span {
943
944
self . top_user_relevant_frame ( )
944
945
. map ( |frame_idx| self . stack ( ) [ frame_idx] . current_span ( ) )
@@ -953,10 +954,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
953
954
pub fn caller_span ( & self ) -> Span {
954
955
// We need to go down at least to the caller (len - 2), or however
955
956
// far we have to go to find a frame in a local crate which is also not #[track_caller].
956
- self . top_user_relevant_frame ( )
957
- . map ( |frame_idx| cmp:: min ( frame_idx, self . stack ( ) . len ( ) - 2 ) )
958
- . map ( |frame_idx| self . stack ( ) [ frame_idx] . current_span ( ) )
959
- . unwrap_or ( rustc_span:: DUMMY_SP )
957
+ let frame_idx = self . top_user_relevant_frame ( ) . unwrap ( ) ;
958
+ let frame_idx = cmp:: min ( frame_idx, self . stack ( ) . len ( ) . checked_sub ( 2 ) . unwrap ( ) ) ;
959
+ self . stack ( ) [ frame_idx] . current_span ( )
960
960
}
961
961
962
962
fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , Provenance , machine:: FrameData < ' tcx > > ] {
0 commit comments