Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2117817

Browse files
committed
Miri stacktrace: record span inside frame, not call-site span
1 parent 8926bb4 commit 2117817

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

src/librustc_middle/mir/interpret/error.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ pub struct ConstEvalErr<'tcx> {
5353

5454
#[derive(Debug)]
5555
pub struct FrameInfo<'tcx> {
56-
/// This span is in the caller.
57-
pub call_site: Span,
5856
pub instance: ty::Instance<'tcx>,
57+
pub span: Span,
5958
pub lint_root: Option<hir::HirId>,
6059
}
6160

@@ -65,12 +64,12 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
6564
if tcx.def_key(self.instance.def_id()).disambiguated_data.data
6665
== DefPathData::ClosureExpr
6766
{
68-
write!(f, "inside call to closure")?;
67+
write!(f, "inside closure")?;
6968
} else {
70-
write!(f, "inside call to `{}`", self.instance)?;
69+
write!(f, "inside `{}`", self.instance)?;
7170
}
72-
if !self.call_site.is_dummy() {
73-
let lo = tcx.sess.source_map().lookup_char_pos(self.call_site.lo());
71+
if !self.span.is_dummy() {
72+
let lo = tcx.sess.source_map().lookup_char_pos(self.span.lo());
7473
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
7574
}
7675
Ok(())
@@ -169,13 +168,9 @@ impl<'tcx> ConstEvalErr<'tcx> {
169168
err.span_label(self.span, span_msg);
170169
}
171170
// Add spans for the stacktrace.
172-
// Skip the last, which is just the environment of the constant. The stacktrace
173-
// is sometimes empty because we create "fake" eval contexts in CTFE to do work
174-
// on constant values.
175-
if !self.stacktrace.is_empty() {
176-
for frame_info in &self.stacktrace[..self.stacktrace.len() - 1] {
177-
err.span_label(frame_info.call_site, frame_info.to_string());
178-
}
171+
// Skip the first, which is the place of the error.
172+
for frame_info in self.stacktrace.iter().skip(1) {
173+
err.span_label(frame_info.span, frame_info.to_string());
179174
}
180175
// Let the caller finish the job.
181176
emit(err)

src/librustc_mir/interpret/eval_context.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -860,30 +860,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
860860
}
861861

862862
pub fn generate_stacktrace(&self, explicit_span: Option<Span>) -> Vec<FrameInfo<'tcx>> {
863-
let mut last_span = None;
864863
let mut frames = Vec::new();
865864
for frame in self.stack().iter().rev() {
866-
// make sure we don't emit frames that are duplicates of the previous
867-
if explicit_span == Some(frame.span) {
868-
last_span = Some(frame.span);
869-
continue;
870-
}
871-
if let Some(last) = last_span {
872-
if last == frame.span {
873-
continue;
874-
}
875-
} else {
876-
last_span = Some(frame.span);
877-
}
878-
879-
let lint_root = frame.current_source_info().and_then(|source_info| {
865+
let source_info = frame.current_source_info();
866+
let lint_root = source_info.and_then(|source_info| {
880867
match &frame.body.source_scopes[source_info.scope].local_data {
881868
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
882869
mir::ClearCrossCrate::Clear => None,
883870
}
884871
});
872+
let span = source_info.map_or(DUMMY_SP, |source_info| source_info.span);
885873

886-
frames.push(FrameInfo { call_site: frame.span, instance: frame.instance, lint_root });
874+
frames.push(FrameInfo { span, instance: frame.instance, lint_root });
887875
}
888876
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
889877
frames

0 commit comments

Comments
 (0)