Skip to content

Commit 1dfb596

Browse files
committed
compiler: Lower fn call arg spans down to MIR
To enable improved accuracy of diagnostics in upcoming commits.
1 parent 57ef889 commit 1dfb596

File tree

46 files changed

+231
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+231
-135
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc_middle::util::CallKind;
2323
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2424
use rustc_span::def_id::LocalDefId;
2525
use rustc_span::hygiene::DesugaringKind;
26+
use rustc_span::source_map::Spanned;
2627
use rustc_span::symbol::{kw, sym, Ident};
2728
use rustc_span::{BytePos, Span, Symbol};
2829
use rustc_trait_selection::infer::InferCtxtExt;
@@ -1247,7 +1248,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12471248
return None;
12481249
};
12491250
debug!("checking call args for uses of inner_param: {:?}", args);
1250-
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
1251+
args.iter()
1252+
.map(|a| &a.node)
1253+
.any(|a| a == &Operand::Move(inner_param))
1254+
.then_some((loc, term))
12511255
})
12521256
else {
12531257
debug!("no uses of inner_param found as a by-move call arg");
@@ -3172,7 +3176,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
31723176
assigned_to, args
31733177
);
31743178
for operand in args {
3175-
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand
3179+
let Spanned {
3180+
node: Operand::Copy(assigned_from) | Operand::Move(assigned_from),
3181+
..
3182+
} = operand
31763183
else {
31773184
continue;
31783185
};

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
635635
);
636636
// Check if one of the arguments to this function is the target place.
637637
let found_target = args.iter().any(|arg| {
638-
if let Operand::Move(place) = arg {
638+
if let Operand::Move(place) = arg.node {
639639
if let Some(potential) = place.as_local() {
640640
potential == target
641641
} else {

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2222
use rustc_middle::util::{call_kind, CallDesugaringKind};
2323
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
2424
use rustc_span::def_id::LocalDefId;
25+
use rustc_span::source_map::Spanned;
2526
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
2627
use rustc_target::abi::{FieldIdx, VariantIdx};
2728
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
@@ -110,9 +111,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
110111
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
111112
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
112113
let closure = match args.first() {
113-
Some(Operand::Copy(place) | Operand::Move(place))
114-
if target == place.local_or_deref_local() =>
115-
{
114+
Some(Spanned {
115+
node: Operand::Copy(place) | Operand::Move(place), ..
116+
}) if target == place.local_or_deref_local() => {
116117
place.local_or_deref_local().unwrap()
117118
}
118119
_ => return false,

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
133133
} => {
134134
self.consume_operand(location, func);
135135
for arg in args {
136-
self.consume_operand(location, arg);
136+
self.consume_operand(location, &arg.node);
137137
}
138138
self.mutate_place(location, *destination, Deep);
139139
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
715715
} => {
716716
self.consume_operand(loc, (func, span), flow_state);
717717
for arg in args {
718-
self.consume_operand(loc, (arg, span), flow_state);
718+
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
719719
}
720720
self.mutate_place(loc, (*destination, span), Deep, flow_state);
721721
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use rustc_middle::ty::{
3838
};
3939
use rustc_middle::ty::{GenericArgsRef, UserArgs};
4040
use rustc_span::def_id::CRATE_DEF_ID;
41+
use rustc_span::source_map::Spanned;
4142
use rustc_span::symbol::sym;
4243
use rustc_span::{Span, DUMMY_SP};
4344
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
@@ -1372,7 +1373,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13721373
TerminatorKind::Call { func, args, destination, call_source, target, .. } => {
13731374
self.check_operand(func, term_location);
13741375
for arg in args {
1375-
self.check_operand(arg, term_location);
1376+
self.check_operand(&arg.node, term_location);
13761377
}
13771378

13781379
let func_ty = func.ty(body, tcx);
@@ -1571,7 +1572,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15711572
term: &Terminator<'tcx>,
15721573
func: &Operand<'tcx>,
15731574
sig: &ty::FnSig<'tcx>,
1574-
args: &[Operand<'tcx>],
1575+
args: &[Spanned<Operand<'tcx>>],
15751576
term_location: Location,
15761577
call_source: CallSource,
15771578
) {
@@ -1584,7 +1585,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15841585
if self.tcx().is_intrinsic(def_id) {
15851586
match self.tcx().item_name(def_id) {
15861587
sym::simd_shuffle => {
1587-
if !matches!(args[2], Operand::Constant(_)) {
1588+
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
15881589
self.tcx()
15891590
.sess
15901591
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
@@ -1597,7 +1598,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15971598
debug!(?func_ty);
15981599

15991600
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
1600-
let op_arg_ty = op_arg.ty(body, self.tcx());
1601+
let op_arg_ty = op_arg.node.ty(body, self.tcx());
16011602

16021603
let op_arg_ty = self.normalize(op_arg_ty, term_location);
16031604
let category = if call_source.from_hir_call() {

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use cranelift_module::ModuleError;
1111
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1212
use rustc_middle::ty::layout::FnAbiOf;
1313
use rustc_session::Session;
14+
use rustc_span::source_map::Spanned;
1415
use rustc_target::abi::call::{Conv, FnAbi};
1516
use rustc_target::spec::abi::Abi;
1617

@@ -355,19 +356,19 @@ struct CallArgument<'tcx> {
355356
// FIXME avoid intermediate `CValue` before calling `adjust_arg_for_abi`
356357
fn codegen_call_argument_operand<'tcx>(
357358
fx: &mut FunctionCx<'_, '_, 'tcx>,
358-
operand: &Operand<'tcx>,
359+
operand: &Spanned<Operand<'tcx>>,
359360
) -> CallArgument<'tcx> {
360361
CallArgument {
361-
value: codegen_operand(fx, operand),
362-
is_owned: matches!(operand, Operand::Move(_)),
362+
value: codegen_operand(fx, &operand.node),
363+
is_owned: matches!(operand.node, Operand::Move(_)),
363364
}
364365
}
365366

366367
pub(crate) fn codegen_terminator_call<'tcx>(
367368
fx: &mut FunctionCx<'_, '_, 'tcx>,
368369
source_info: mir::SourceInfo,
369370
func: &Operand<'tcx>,
370-
args: &[Operand<'tcx>],
371+
args: &[Spanned<Operand<'tcx>>],
371372
destination: Place<'tcx>,
372373
target: Option<BasicBlock>,
373374
) {
@@ -421,7 +422,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
421422

422423
let extra_args = &args[fn_sig.inputs().skip_binder().len()..];
423424
let extra_args = fx.tcx.mk_type_list_from_iter(
424-
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))),
425+
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))),
425426
);
426427
let fn_abi = if let Some(instance) = instance {
427428
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)

compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Emulate LLVM intrinsics
22
33
use rustc_middle::ty::GenericArgsRef;
4+
use rustc_span::source_map::Spanned;
45

56
use crate::intrinsics::*;
67
use crate::prelude::*;
@@ -9,7 +10,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
910
fx: &mut FunctionCx<'_, '_, 'tcx>,
1011
intrinsic: &str,
1112
generic_args: GenericArgsRef<'tcx>,
12-
args: &[mir::Operand<'tcx>],
13+
args: &[Spanned<mir::Operand<'tcx>>],
1314
ret: CPlace<'tcx>,
1415
target: Option<BasicBlock>,
1516
) {

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_aarch64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
99
fx: &mut FunctionCx<'_, '_, 'tcx>,
1010
intrinsic: &str,
1111
_args: GenericArgsRef<'tcx>,
12-
args: &[mir::Operand<'tcx>],
12+
args: &[Spanned<mir::Operand<'tcx>>],
1313
ret: CPlace<'tcx>,
1414
target: Option<BasicBlock>,
1515
) {

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
99
fx: &mut FunctionCx<'_, '_, 'tcx>,
1010
intrinsic: &str,
1111
_args: GenericArgsRef<'tcx>,
12-
args: &[mir::Operand<'tcx>],
12+
args: &[Spanned<mir::Operand<'tcx>>],
1313
ret: CPlace<'tcx>,
1414
target: Option<BasicBlock>,
1515
) {
@@ -72,9 +72,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
7272
[x, y, kind] => (x, y, kind),
7373
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
7474
};
75-
let x = codegen_operand(fx, x);
76-
let y = codegen_operand(fx, y);
77-
let kind = match kind {
75+
let x = codegen_operand(fx, &x.node);
76+
let y = codegen_operand(fx, &y.node);
77+
let kind = match &kind.node {
7878
Operand::Constant(const_) => crate::constant::eval_mir_constant(fx, const_).0,
7979
Operand::Copy(_) | Operand::Move(_) => unreachable!("{kind:?}"),
8080
};
@@ -184,8 +184,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
184184
[a, b] => (a, b),
185185
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
186186
};
187-
let a = codegen_operand(fx, a);
188-
let b = codegen_operand(fx, b);
187+
let a = codegen_operand(fx, &a.node);
188+
let b = codegen_operand(fx, &b.node);
189189

190190
// Based on the pseudocode at https://github.com/rust-lang/stdarch/blob/1cfbca8b38fd9b4282b2f054f61c6ca69fc7ce29/crates/core_arch/src/x86/avx2.rs#L2319-L2332
191191
let zero = fx.bcx.ins().iconst(types::I8, 0);
@@ -218,9 +218,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
218218
[a, b, imm8] => (a, b, imm8),
219219
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
220220
};
221-
let a = codegen_operand(fx, a);
222-
let b = codegen_operand(fx, b);
223-
let imm8 = codegen_operand(fx, imm8).load_scalar(fx);
221+
let a = codegen_operand(fx, &a.node);
222+
let b = codegen_operand(fx, &b.node);
223+
let imm8 = codegen_operand(fx, &imm8.node).load_scalar(fx);
224224

225225
let a_0 = a.value_lane(fx, 0).load_scalar(fx);
226226
let a_1 = a.value_lane(fx, 1).load_scalar(fx);
@@ -275,7 +275,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
275275
[a] => a,
276276
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
277277
};
278-
let a = codegen_operand(fx, a);
278+
let a = codegen_operand(fx, &a.node);
279279

280280
simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| {
281281
fx.bcx.ins().iabs(lane)

0 commit comments

Comments
 (0)