Skip to content

Commit d6c988b

Browse files
committed
miri: fall back to whole-function span when loc==None
1 parent 5154b66 commit d6c988b

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::ty::layout::{self, TyAndLayout};
1616
use rustc_middle::ty::{
1717
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
1818
};
19-
use rustc_span::{source_map::DUMMY_SP, Pos, Span};
19+
use rustc_span::{Pos, Span};
2020
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
2121

2222
use super::{
@@ -191,6 +191,10 @@ impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> {
191191
pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
192192
self.loc.map(|loc| self.body.source_info(loc))
193193
}
194+
195+
pub fn current_span(&self) -> Span {
196+
self.current_source_info().map(|si| si.span).unwrap_or(self.body.span)
197+
}
194198
}
195199

196200
impl<'tcx> fmt::Display for FrameInfo<'tcx> {
@@ -324,11 +328,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
324328

325329
#[inline(always)]
326330
pub fn cur_span(&self) -> Span {
327-
self.stack()
328-
.last()
329-
.and_then(|f| f.current_source_info())
330-
.map(|si| si.span)
331-
.unwrap_or(self.tcx.span)
331+
self.stack().last().map(|f| f.current_span()).unwrap_or(self.tcx.span)
332332
}
333333

334334
#[inline(always)]
@@ -921,14 +921,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
921921
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
922922
let mut frames = Vec::new();
923923
for frame in self.stack().iter().rev() {
924-
let source_info = frame.current_source_info();
925-
let lint_root = source_info.and_then(|source_info| {
924+
let lint_root = frame.current_source_info().and_then(|source_info| {
926925
match &frame.body.source_scopes[source_info.scope].local_data {
927926
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
928927
mir::ClearCrossCrate::Clear => None,
929928
}
930929
});
931-
let span = source_info.map_or(DUMMY_SP, |source_info| source_info.span);
930+
let span = frame.current_span();
932931

933932
frames.push(FrameInfo { span, instance: frame.instance, lint_root });
934933
}

src/librustc_mir/interpret/intrinsics/caller_location.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3030
// Assert that there is always such a frame.
3131
.unwrap();
3232
// Assert that the frame we look at is actually executing code currently
33-
// (`current_source_info` is None when we are unwinding and the frame does
34-
// not require cleanup).
33+
// (`loc` is None when we are unwinding and the frame does not require cleanup).
3534
let loc = frame.loc.unwrap();
3635
// If this is a `Call` terminator, use the `fn_span` instead.
3736
let block = &frame.body.basic_blocks()[loc.block];

0 commit comments

Comments
 (0)