Skip to content

Commit c8743db

Browse files
committed
add and use helper method to get SourceInfo of current instruction in frame
1 parent 56356a0 commit c8743db

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
164164
}
165165
}
166166

167+
impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> {
168+
/// Return the `SourceInfo` of the current instruction.
169+
pub fn current_source_info(&self) -> Option<mir::SourceInfo> {
170+
self.block.map(|block| {
171+
let block = &self.body.basic_blocks()[block];
172+
if self.stmt < block.statements.len() {
173+
block.statements[self.stmt].source_info
174+
} else {
175+
block.terminator().source_info
176+
}
177+
})
178+
}
179+
}
180+
167181
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpCx<'mir, 'tcx, M> {
168182
#[inline]
169183
fn data_layout(&self) -> &layout::TargetDataLayout {
@@ -828,34 +842,28 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
828842
pub fn generate_stacktrace(&self, explicit_span: Option<Span>) -> Vec<FrameInfo<'tcx>> {
829843
let mut last_span = None;
830844
let mut frames = Vec::new();
831-
for &Frame { instance, span, body, block, stmt, .. } in self.stack().iter().rev() {
845+
for frame in self.stack().iter().rev() {
832846
// make sure we don't emit frames that are duplicates of the previous
833-
if explicit_span == Some(span) {
834-
last_span = Some(span);
847+
if explicit_span == Some(frame.span) {
848+
last_span = Some(frame.span);
835849
continue;
836850
}
837851
if let Some(last) = last_span {
838-
if last == span {
852+
if last == frame.span {
839853
continue;
840854
}
841855
} else {
842-
last_span = Some(span);
856+
last_span = Some(frame.span);
843857
}
844858

845-
let lint_root = block.and_then(|block| {
846-
let block = &body.basic_blocks()[block];
847-
let source_info = if stmt < block.statements.len() {
848-
block.statements[stmt].source_info
849-
} else {
850-
block.terminator().source_info
851-
};
852-
match &body.source_scopes[source_info.scope].local_data {
859+
let lint_root = frame.current_source_info().and_then(|source_info| {
860+
match &frame.body.source_scopes[source_info.scope].local_data {
853861
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
854862
mir::ClearCrossCrate::Clear => None,
855863
}
856864
});
857865

858-
frames.push(FrameInfo { call_site: span, instance, lint_root });
866+
frames.push(FrameInfo { call_site: frame.span, instance: frame.instance, lint_root });
859867
}
860868
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
861869
frames

0 commit comments

Comments
 (0)