1
Fork 0

interpret: do not prune requires_caller_location stack frames quite so early

This commit is contained in:
Ralf Jung 2022-06-26 14:42:26 -04:00
parent 1aabd8a4a6
commit 852a111133
3 changed files with 13 additions and 18 deletions

View file

@ -82,12 +82,12 @@ impl<'tcx> ConstEvalErr<'tcx> {
'tcx: 'mir, 'tcx: 'mir,
{ {
error.print_backtrace(); error.print_backtrace();
let stacktrace = ecx.generate_stacktrace(); let mut stacktrace = ecx.generate_stacktrace();
ConstEvalErr { // Filter out `requires_caller_location` frames.
error: error.into_kind(), stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
stacktrace, // If `span` is missing, use topmost remaining frame, or else the "root" span from `ecx.tcx`.
span: span.unwrap_or_else(|| ecx.cur_span()), let span = span.or_else(|| stacktrace.first().map(|f| f.span)).unwrap_or(ecx.tcx.span);
} ConstEvalErr { error: error.into_kind(), stacktrace, span }
} }
pub fn struct_error( pub fn struct_error(

View file

@ -337,7 +337,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
} }
}; };
Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), &msg)) Err(err.report_as_error(ecx.tcx.at(err.span), &msg))
} else { } else {
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did); let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
Err(err.report_as_lint( Err(err.report_as_lint(

View file

@ -428,11 +428,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
#[inline(always)] #[inline(always)]
pub fn cur_span(&self) -> Span { pub fn cur_span(&self) -> Span {
self.stack() // This deliberately does *not* honor `requires_caller_location` since it is used for much
.iter() // more than just panics.
.rev() self.stack().last().map_or(self.tcx.span, |f| f.current_span())
.find(|frame| !frame.instance.def.requires_caller_location(*self.tcx))
.map_or(self.tcx.span, |f| f.current_span())
} }
#[inline(always)] #[inline(always)]
@ -939,12 +937,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
#[must_use] #[must_use]
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> { pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
let mut frames = Vec::new(); let mut frames = Vec::new();
for frame in self // This deliberately does *not* honor `requires_caller_location` since it is used for much
.stack() // more than just panics.
.iter() for frame in self.stack().iter().rev() {
.rev()
.skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx))
{
let lint_root = frame.current_source_info().and_then(|source_info| { let lint_root = frame.current_source_info().and_then(|source_info| {
match &frame.body.source_scopes[source_info.scope].local_data { match &frame.body.source_scopes[source_info.scope].local_data {
mir::ClearCrossCrate::Set(data) => Some(data.lint_root), mir::ClearCrossCrate::Set(data) => Some(data.lint_root),