compiler: Lower fn call arg spans down to MIR
To enable improved accuracy of diagnostics in upcoming commits.
This commit is contained in:
parent
924ea05103
commit
16ba56c242
47 changed files with 221 additions and 170 deletions
|
@ -2,6 +2,7 @@ use rustc_middle::mir::interpret::Scalar;
|
|||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::ty::cast::mir_cast_kind;
|
||||
use rustc_middle::{mir::*, thir::*, ty};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
|
||||
|
@ -162,7 +163,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
let fun = self.parse_operand(*fun)?;
|
||||
let args = args
|
||||
.iter()
|
||||
.map(|arg| self.parse_operand(*arg))
|
||||
.map(|arg|
|
||||
Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } )
|
||||
)
|
||||
.collect::<PResult<Vec<_>>>()?;
|
||||
Ok(TerminatorKind::Call {
|
||||
func: fun,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_target::abi::{Abi, FieldIdx, Primitive};
|
||||
|
||||
use crate::build::expr::as_place::PlaceBase;
|
||||
|
@ -15,7 +16,7 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
use rustc_middle::ty::{self, Ty, UpvarArgs};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Returns an rvalue suitable for use until the end of the current
|
||||
|
@ -156,7 +157,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
synth_info,
|
||||
TerminatorKind::Call {
|
||||
func: exchange_malloc,
|
||||
args: vec![Operand::Move(size), Operand::Move(align)],
|
||||
args: vec![
|
||||
Spanned { node: Operand::Move(size), span: DUMMY_SP },
|
||||
Spanned { node: Operand::Move(align), span: DUMMY_SP },
|
||||
],
|
||||
destination: storage,
|
||||
target: Some(success),
|
||||
unwind: UnwindAction::Continue,
|
||||
|
@ -733,7 +737,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
this.diverge_from(block);
|
||||
block = success;
|
||||
}
|
||||
this.record_operands_moved(&[value_operand]);
|
||||
this.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]);
|
||||
}
|
||||
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new()))
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_hir as hir;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use std::iter;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
@ -248,7 +249,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let args: Vec<_> = args
|
||||
.into_iter()
|
||||
.copied()
|
||||
.map(|arg| unpack!(block = this.as_local_call_operand(block, arg)))
|
||||
.map(|arg| Spanned {
|
||||
node: unpack!(block = this.as_local_call_operand(block, arg)),
|
||||
span: this.thir.exprs[arg].span,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let success = this.cfg.start_new_block();
|
||||
|
|
|
@ -17,8 +17,9 @@ use rustc_middle::ty::util::IntTypeExt;
|
|||
use rustc_middle::ty::GenericArg;
|
||||
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
@ -271,7 +272,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
user_ty: None,
|
||||
const_: method,
|
||||
})),
|
||||
args: vec![Operand::Move(ref_string)],
|
||||
args: vec![Spanned { node: Operand::Move(ref_string), span: DUMMY_SP }],
|
||||
destination: ref_str,
|
||||
target: Some(eq_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
|
@ -526,7 +527,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
const_: method,
|
||||
})),
|
||||
args: vec![Operand::Copy(val), expect],
|
||||
args: vec![
|
||||
Spanned { node: Operand::Copy(val), span: DUMMY_SP },
|
||||
Spanned { node: expect, span: DUMMY_SP },
|
||||
],
|
||||
destination: eq_result,
|
||||
target: Some(eq_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
|
|
|
@ -91,6 +91,7 @@ use rustc_middle::middle::region;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::thir::{ExprId, LintLevel};
|
||||
use rustc_session::lint::Level;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -1020,14 +1021,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
/// spurious borrow-check errors -- the problem, ironically, is
|
||||
/// not the `DROP(_X)` itself, but the (spurious) unwind pathways
|
||||
/// that it creates. See #64391 for an example.
|
||||
pub(crate) fn record_operands_moved(&mut self, operands: &[Operand<'tcx>]) {
|
||||
pub(crate) fn record_operands_moved(&mut self, operands: &[Spanned<Operand<'tcx>>]) {
|
||||
let local_scope = self.local_scope();
|
||||
let scope = self.scopes.scopes.last_mut().unwrap();
|
||||
|
||||
assert_eq!(scope.region_scope, local_scope, "local scope is not the topmost scope!",);
|
||||
|
||||
// look for moves of a local variable, like `MOVE(_X)`
|
||||
let locals_moved = operands.iter().flat_map(|operand| match operand {
|
||||
let locals_moved = operands.iter().flat_map(|operand| match operand.node {
|
||||
Operand::Copy(_) | Operand::Constant(_) => None,
|
||||
Operand::Move(place) => place.as_local(),
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue