set span more accurately during const_prop
This commit is contained in:
parent
fb9b693acc
commit
43cdfbb3fe
3 changed files with 13 additions and 7 deletions
|
@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{self, TyAndLayout};
|
|||
use rustc_middle::ty::{
|
||||
self, fold::BottomUpFolder, query::TyCtxtAt, subst::SubstsRef, Ty, TyCtxt, TypeFoldable,
|
||||
};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
use rustc_span::{source_map::DUMMY_SP, Span};
|
||||
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
|
||||
|
||||
use super::{
|
||||
|
@ -296,6 +296,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_span(&mut self, span: Span) {
|
||||
self.tcx.span = span;
|
||||
self.memory.tcx.span = span;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn force_ptr(
|
||||
&self,
|
||||
|
|
|
@ -78,14 +78,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> {
|
||||
info!("{:?}", stmt);
|
||||
self.set_span(stmt.source_info.span);
|
||||
|
||||
use rustc_middle::mir::StatementKind::*;
|
||||
|
||||
// Some statements (e.g., box) push new stack frames.
|
||||
// We have to record the stack frame number *before* executing the statement.
|
||||
let frame_idx = self.cur_frame();
|
||||
self.tcx.span = stmt.source_info.span;
|
||||
self.memory.tcx.span = stmt.source_info.span;
|
||||
|
||||
match &stmt.kind {
|
||||
Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?,
|
||||
|
@ -276,8 +275,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> {
|
||||
info!("{:?}", terminator.kind);
|
||||
self.tcx.span = terminator.source_info.span;
|
||||
self.memory.tcx.span = terminator.source_info.span;
|
||||
self.set_span(terminator.source_info.span);
|
||||
|
||||
self.eval_terminator(terminator)?;
|
||||
if !self.stack.is_empty() {
|
||||
|
|
|
@ -425,8 +425,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
}
|
||||
|
||||
fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
|
||||
self.ecx.tcx.span = c.span;
|
||||
|
||||
// FIXME we need to revisit this for #67176
|
||||
if c.needs_subst() {
|
||||
return None;
|
||||
|
@ -435,6 +433,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
match self.ecx.eval_const_to_op(c.literal, None) {
|
||||
Ok(op) => Some(op),
|
||||
Err(error) => {
|
||||
// Make sure errors point at the constant.
|
||||
self.ecx.set_span(c.span);
|
||||
let err = error_to_const_error(&self.ecx, error);
|
||||
if let Some(lint_root) = self.lint_root(source_info) {
|
||||
let lint_only = match c.literal.val {
|
||||
|
@ -820,6 +820,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
|
|||
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
|
||||
trace!("visit_statement: {:?}", statement);
|
||||
let source_info = statement.source_info;
|
||||
self.ecx.set_span(source_info.span);
|
||||
self.source_info = Some(source_info);
|
||||
if let StatementKind::Assign(box (place, ref mut rval)) = statement.kind {
|
||||
let place_ty: Ty<'tcx> = place.ty(&self.local_decls, self.tcx).ty;
|
||||
|
@ -870,6 +871,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
|
|||
|
||||
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
|
||||
let source_info = terminator.source_info;
|
||||
self.ecx.set_span(source_info.span);
|
||||
self.source_info = Some(source_info);
|
||||
self.super_terminator(terminator, location);
|
||||
match &mut terminator.kind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue