Skip to content

Commit 852a111

Browse files
committed
interpret: do not prune requires_caller_location stack frames quite so early
1 parent 1aabd8a commit 852a111

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ impl<'tcx> ConstEvalErr<'tcx> {
8282
'tcx: 'mir,
8383
{
8484
error.print_backtrace();
85-
let stacktrace = ecx.generate_stacktrace();
86-
ConstEvalErr {
87-
error: error.into_kind(),
88-
stacktrace,
89-
span: span.unwrap_or_else(|| ecx.cur_span()),
90-
}
85+
let mut stacktrace = ecx.generate_stacktrace();
86+
// Filter out `requires_caller_location` frames.
87+
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
88+
// If `span` is missing, use topmost remaining frame, or else the "root" span from `ecx.tcx`.
89+
let span = span.or_else(|| stacktrace.first().map(|f| f.span)).unwrap_or(ecx.tcx.span);
90+
ConstEvalErr { error: error.into_kind(), stacktrace, span }
9191
}
9292

9393
pub fn struct_error(

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
337337
}
338338
};
339339

340-
Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), &msg))
340+
Err(err.report_as_error(ecx.tcx.at(err.span), &msg))
341341
} else {
342342
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
343343
Err(err.report_as_lint(

compiler/rustc_const_eval/src/interpret/eval_context.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
428428

429429
#[inline(always)]
430430
pub fn cur_span(&self) -> Span {
431-
self.stack()
432-
.iter()
433-
.rev()
434-
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
435-
.map_or(self.tcx.span, |f| f.current_span())
431+
// This deliberately does *not* honor `requires_caller_location` since it is used for much
432+
// more than just panics.
433+
self.stack().last().map_or(self.tcx.span, |f| f.current_span())
436434
}
437435

438436
#[inline(always)]
@@ -939,12 +937,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
939937
#[must_use]
940938
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
941939
let mut frames = Vec::new();
942-
for frame in self
943-
.stack()
944-
.iter()
945-
.rev()
946-
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
947-
{
940+
// This deliberately does *not* honor `requires_caller_location` since it is used for much
941+
// more than just panics.
942+
for frame in self.stack().iter().rev() {
948943
let lint_root = frame.current_source_info().and_then(|source_info| {
949944
match &frame.body.source_scopes[source_info.scope].local_data {
950945
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),

0 commit comments

Comments
 (0)