@@ -939,6 +939,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
939939 /// Get the current span in the topmost function which is workspace-local and not
940940 /// `#[track_caller]`.
941941 /// 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.
942943 pub fn current_span ( & self ) -> Span {
943944 self . top_user_relevant_frame ( )
944945 . map ( |frame_idx| self . stack ( ) [ frame_idx] . current_span ( ) )
@@ -953,10 +954,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
953954 pub fn caller_span ( & self ) -> Span {
954955 // We need to go down at least to the caller (len - 2), or however
955956 // 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 ( )
960960 }
961961
962962 fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , Provenance , machine:: FrameData < ' tcx > > ] {
0 commit comments