about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-11-26 14:01:05 +0100
committerRalf Jung <post@ralfj.de>2022-11-26 14:01:26 +0100
commit726b9d09d420e8b94428170f3e8a637f54928f50 (patch)
treee190f690e1e1d767972feb0c301c97c14bf5b051 /src
parent8961e13802946e3c956b8f9657aaabf2978027b6 (diff)
downloadrust-726b9d09d420e8b94428170f3e8a637f54928f50.tar.gz
rust-726b9d09d420e8b94428170f3e8a637f54928f50.zip
caller_span only makes sense when there are 2 frames on the stack
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/src/helpers.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index cfa47c5c004..8c7bc9eff00 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -939,6 +939,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
     /// Get the current span in the topmost function which is workspace-local and not
     /// `#[track_caller]`.
     /// This function is backed by a cache, and can be assumed to be very fast.
+    /// It will work even when the stack is empty.
     pub fn current_span(&self) -> Span {
         self.top_user_relevant_frame()
             .map(|frame_idx| self.stack()[frame_idx].current_span())
@@ -953,10 +954,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
     pub fn caller_span(&self) -> Span {
         // We need to go down at least to the caller (len - 2), or however
         // far we have to go to find a frame in a local crate which is also not #[track_caller].
-        self.top_user_relevant_frame()
-            .map(|frame_idx| cmp::min(frame_idx, self.stack().len() - 2))
-            .map(|frame_idx| self.stack()[frame_idx].current_span())
-            .unwrap_or(rustc_span::DUMMY_SP)
+        let frame_idx = self.top_user_relevant_frame().unwrap();
+        let frame_idx = cmp::min(frame_idx, self.stack().len().checked_sub(2).unwrap());
+        self.stack()[frame_idx].current_span()
     }
 
     fn stack(&self) -> &[Frame<'mir, 'tcx, Provenance, machine::FrameData<'tcx>>] {