Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn get_span_and_frames<'tcx>(
tcx: TyCtxtAt<'tcx>,
stack: &[Frame<'tcx, impl Provenance, impl Sized>],
) -> (Span, Vec<errors::FrameNote>) {
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack, *tcx);
// Filter out `requires_caller_location` frames.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
let span = stacktrace.last().map(|f| f.span).unwrap_or(tcx.span);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {

#[must_use]
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
Frame::generate_stacktrace_from_stack(self.stack())
Frame::generate_stacktrace_from_stack(self.stack(), *self.tcx)
}

pub fn adjust_nan<F1, F2>(&self, f: F2, inputs: &[F1]) -> F2
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_const_eval/src/interpret/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,15 @@ impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
}

#[must_use]
pub fn generate_stacktrace_from_stack(stack: &[Self]) -> Vec<FrameInfo<'tcx>> {
pub fn generate_stacktrace_from_stack(
stack: &[Self],
tcx: TyCtxt<'tcx>,
) -> Vec<FrameInfo<'tcx>> {
let mut frames = Vec::new();
// This deliberately does *not* honor `requires_caller_location` since it is used for much
// more than just panics.
for frame in stack.iter().rev() {
let span = match frame.loc {
let mut span = match frame.loc {
Left(loc) => {
// If the stacktrace passes through MIR-inlined source scopes, add them.
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
Expand All @@ -340,6 +343,10 @@ impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
}
Right(span) => span,
};
if span.is_dummy() {
// Some statements lack a proper span; point at the function instead.
span = tcx.def_span(frame.instance.def_id());
}
frames.push(FrameInfo { span, instance: frame.instance });
}
trace!("generate stacktrace: {:#?}", frames);
Expand Down
5 changes: 3 additions & 2 deletions src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub fn report_result<'tcx>(
// The "active" thread might actually be terminated, so we ignore it.
let mut any_pruned = false;
for (thread, stack) in ecx.machine.threads.all_blocked_stacks() {
let stacktrace = Frame::generate_stacktrace_from_stack(stack);
let stacktrace = Frame::generate_stacktrace_from_stack(stack, *ecx.tcx);
let (stacktrace, was_pruned) = prune_stacktrace(stacktrace, &ecx.machine);
any_pruned |= was_pruned;
report_msg(
Expand Down Expand Up @@ -633,7 +633,8 @@ impl<'tcx> MiriMachine<'tcx> {
pub fn emit_diagnostic(&self, e: NonHaltingDiagnostic) {
use NonHaltingDiagnostic::*;

let stacktrace = Frame::generate_stacktrace_from_stack(self.threads.active_thread_stack());
let stacktrace =
Frame::generate_stacktrace_from_stack(self.threads.active_thread_stack(), self.tcx);
let (stacktrace, _was_pruned) = prune_stacktrace(stacktrace, self);

let (label, diag_level) = match &e {
Expand Down
Loading