1
Fork 0

Directly pass in the stack instead of computing it from a machine

This commit is contained in:
Oli Scherer 2024-03-11 13:21:42 +00:00
parent d2d2bd2736
commit d3b7b558aa
2 changed files with 6 additions and 5 deletions

View file

@ -2,6 +2,7 @@ use std::mem;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg}; use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg};
use rustc_hir::CRATE_HIR_ID; use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::interpret::Provenance;
use rustc_middle::mir::AssertKind; use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt; use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -58,12 +59,12 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
pub fn get_span_and_frames<'tcx, 'mir>( pub fn get_span_and_frames<'tcx, 'mir>(
tcx: TyCtxtAt<'tcx>, tcx: TyCtxtAt<'tcx>,
machine: &CompileTimeInterpreter<'mir, 'tcx>, stack: &[Frame<'mir, 'tcx, impl Provenance, impl Sized>],
) -> (Span, Vec<errors::FrameNote>) ) -> (Span, Vec<errors::FrameNote>)
where where
'tcx: 'mir, 'tcx: 'mir,
{ {
let mut stacktrace = Frame::generate_stacktrace_from_stack(&machine.stack); let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
// Filter out `requires_caller_location` frames. // Filter out `requires_caller_location` frames.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx)); stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span); let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span);
@ -167,7 +168,7 @@ pub(super) fn lint<'tcx, 'mir, L>(
) where ) where
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>, L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
{ {
let (span, frames) = get_span_and_frames(tcx, machine); let (span, frames) = get_span_and_frames(tcx, &machine.stack);
tcx.emit_node_span_lint( tcx.emit_node_span_lint(
lint, lint,

View file

@ -385,7 +385,7 @@ fn eval_in_interpreter<'mir, 'tcx, R: InterpretationResult<'tcx>>(
*ecx.tcx, *ecx.tcx,
error, error,
None, None,
|| super::get_span_and_frames(ecx.tcx, &ecx.machine), || super::get_span_and_frames(ecx.tcx, ecx.stack()),
|span, frames| ConstEvalError { |span, frames| ConstEvalError {
span, span,
error_kind: kind, error_kind: kind,
@ -450,7 +450,7 @@ pub fn const_report_error<'mir, 'tcx>(
*ecx.tcx, *ecx.tcx,
error, error,
None, None,
|| crate::const_eval::get_span_and_frames(ecx.tcx, &ecx.machine), || crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()),
move |span, frames| errors::UndefinedBehavior { span, ub_note, frames, raw_bytes }, move |span, frames| errors::UndefinedBehavior { span, ub_note, frames, raw_bytes },
) )
} }