Skip to content

Commit 2553a9a

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

File tree

26 files changed

+74
-19
lines changed

26 files changed

+74
-19
lines changed

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
125125
TerminatorKind::Call {
126126
func,
127127
args,
128+
arg_spans: _,
128129
destination,
129130
target: _,
130131
unwind: _,

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
707707
TerminatorKind::Call {
708708
func,
709709
args,
710+
arg_spans: _,
710711
destination,
711712
target: _,
712713
unwind: _,

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
425425
TerminatorKind::Call {
426426
func,
427427
args,
428+
arg_spans: _,
428429
destination,
429430
target,
430431
fn_span,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12481248
mir::TerminatorKind::Call {
12491249
ref func,
12501250
ref args,
1251+
arg_spans: _,
12511252
destination,
12521253
target,
12531254
unwind,

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
115115
Call {
116116
ref func,
117117
ref args,
118+
arg_spans: _,
118119
destination,
119120
target,
120121
unwind,

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
800800

801801
match terminator.kind {
802802
TerminatorKind::Call {
803-
mut func, mut args, call_source: desugar, fn_span, ..
803+
mut func,
804+
mut args,
805+
arg_spans,
806+
call_source: desugar,
807+
fn_span,
808+
..
804809
} => {
805810
self.visit_operand(&mut func, loc);
806811
for arg in &mut args {
@@ -814,6 +819,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
814819
kind: TerminatorKind::Call {
815820
func,
816821
args,
822+
arg_spans,
817823
unwind: UnwindAction::Continue,
818824
destination: Place::from(new_temp),
819825
target: Some(new_target),

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,13 +1568,13 @@ mod size_asserts {
15681568
use super::*;
15691569
use rustc_data_structures::static_assert_size;
15701570
// tidy-alphabetical-start
1571-
static_assert_size!(BasicBlockData<'_>, 136);
1571+
static_assert_size!(BasicBlockData<'_>, 160);
15721572
static_assert_size!(LocalDecl<'_>, 40);
15731573
static_assert_size!(SourceScopeData<'_>, 72);
15741574
static_assert_size!(Statement<'_>, 32);
15751575
static_assert_size!(StatementKind<'_>, 16);
1576-
static_assert_size!(Terminator<'_>, 104);
1577-
static_assert_size!(TerminatorKind<'_>, 88);
1576+
static_assert_size!(Terminator<'_>, 128);
1577+
static_assert_size!(TerminatorKind<'_>, 112);
15781578
static_assert_size!(VarDebugInfo<'_>, 88);
15791579
// tidy-alphabetical-end
15801580
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ pub enum TerminatorKind<'tcx> {
671671
/// This allows the memory occupied by "by-value" arguments to be
672672
/// reused across function calls without duplicating the contents.
673673
args: Vec<Operand<'tcx>>,
674+
/// The spans of the args
675+
/// (e.g. `a` and `b` in `x.foo(a, b)`).
676+
arg_spans: Vec<Span>,
674677
/// Where the returned value will be written
675678
destination: Place<'tcx>,
676679
/// Where to go after this call returns. If none, the call necessarily diverges.

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,20 @@ impl<'tcx> TerminatorKind<'tcx> {
520520
}
521521
}
522522

523-
Call { unwind, destination, target, func: _, args: _, fn_span: _, call_source: _ } => {
524-
TerminatorEdges::AssignOnReturn {
525-
return_: target,
526-
cleanup: unwind.cleanup_block(),
527-
place: CallReturnPlaces::Call(destination),
528-
}
529-
}
523+
Call {
524+
unwind,
525+
destination,
526+
target,
527+
func: _,
528+
args: _,
529+
fn_span: _,
530+
arg_spans: _,
531+
call_source: _,
532+
} => TerminatorEdges::AssignOnReturn {
533+
return_: target,
534+
cleanup: unwind.cleanup_block(),
535+
place: CallReturnPlaces::Call(destination),
536+
},
530537

531538
InlineAsm {
532539
template: _,

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ macro_rules! make_mir_visitor {
518518
TerminatorKind::Call {
519519
func,
520520
args,
521+
arg_spans: _,
521522
destination,
522523
target: _,
523524
unwind: _,

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_middle::mir::interpret::Scalar;
22
use rustc_middle::mir::tcx::PlaceTy;
33
use rustc_middle::ty::cast::mir_cast_kind;
44
use rustc_middle::{mir::*, thir::*, ty};
5-
use rustc_span::Span;
5+
use rustc_span::{Span, DUMMY_SP};
66
use rustc_target::abi::{FieldIdx, VariantIdx};
77

88
use crate::build::custom::ParseError;
@@ -121,9 +121,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
121121
.iter()
122122
.map(|arg| self.parse_operand(*arg))
123123
.collect::<PResult<Vec<_>>>()?;
124+
let arg_spans = args.iter().map(|_| DUMMY_SP).collect();
124125
Ok(TerminatorKind::Call {
125126
func: fun,
126127
args,
128+
arg_spans,
127129
destination,
128130
target: Some(target),
129131
unwind: UnwindAction::Continue,

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::thir::*;
1717
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
1818
use rustc_middle::ty::layout::IntegerExt;
1919
use rustc_middle::ty::{self, Ty, UpvarArgs};
20-
use rustc_span::Span;
20+
use rustc_span::{Span, DUMMY_SP};
2121

2222
impl<'a, 'tcx> Builder<'a, 'tcx> {
2323
/// Returns an rvalue suitable for use until the end of the current
@@ -170,6 +170,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
170170
TerminatorKind::Call {
171171
func: exchange_malloc,
172172
args: vec![Operand::Move(size), Operand::Move(align)],
173+
arg_spans: vec![DUMMY_SP, DUMMY_SP],
173174
destination: storage,
174175
target: Some(success),
175176
unwind: UnwindAction::Continue,

compiler/rustc_mir_build/src/build/expr/into.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
241241
}
242242
ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => {
243243
let fun = unpack!(block = this.as_local_operand(block, &this.thir[fun]));
244+
let arg_spans =
245+
args.iter().map(|arg| this.thir.exprs[*arg].span).collect::<Vec<_>>();
244246
let args: Vec<_> = args
245247
.into_iter()
246248
.copied()
@@ -259,6 +261,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
259261
TerminatorKind::Call {
260262
func: fun,
261263
args,
264+
arg_spans,
262265
unwind: UnwindAction::Continue,
263266
destination,
264267
// The presence or absence of a return edge affects control-flow sensitive

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::GenericArg;
1919
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
2020
use rustc_span::def_id::DefId;
2121
use rustc_span::symbol::{sym, Symbol};
22-
use rustc_span::Span;
22+
use rustc_span::{Span, DUMMY_SP};
2323
use rustc_target::abi::VariantIdx;
2424

2525
use std::cmp::Ordering;
@@ -258,6 +258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
258258
const_: method,
259259
})),
260260
args: vec![Operand::Move(ref_string)],
261+
arg_spans: vec![DUMMY_SP],
261262
destination: ref_str,
262263
target: Some(eq_block),
263264
unwind: UnwindAction::Continue,
@@ -494,6 +495,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
494495
const_: method,
495496
})),
496497
args: vec![Operand::Copy(val), expect],
498+
arg_spans: vec![DUMMY_SP, DUMMY_SP],
497499
destination: eq_result,
498500
target: Some(eq_block),
499501
unwind: UnwindAction::Continue,

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_middle::traits::Reveal;
77
use rustc_middle::ty::util::IntTypeExt;
88
use rustc_middle::ty::GenericArgsRef;
99
use rustc_middle::ty::{self, Ty, TyCtxt};
10+
use rustc_span::DUMMY_SP;
1011
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
1112
use std::{fmt, iter};
1213

@@ -657,6 +658,7 @@ where
657658
self.source_info.span,
658659
),
659660
args: vec![Operand::Move(Place::from(ref_place))],
661+
arg_spans: vec![DUMMY_SP],
660662
destination: unit_temp,
661663
target: Some(succ),
662664
unwind: unwind.into_action(),

compiler/rustc_mir_dataflow/src/framework/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> {
3737
mir::TerminatorKind::Call {
3838
func: mir::Operand::Copy(dummy_place.clone()),
3939
args: vec![],
40+
arg_spans: vec![],
4041
destination: dummy_place.clone(),
4142
target: Some(mir::START_BLOCK),
4243
unwind: mir::UnwindAction::Continue,
@@ -51,6 +52,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> {
5152
mir::TerminatorKind::Call {
5253
func: mir::Operand::Copy(dummy_place.clone()),
5354
args: vec![],
55+
arg_spans: vec![],
5456
destination: dummy_place.clone(),
5557
target: Some(mir::START_BLOCK),
5658
unwind: mir::UnwindAction::Continue,

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
474474
TerminatorKind::Call {
475475
ref func,
476476
ref args,
477+
arg_spans: _,
477478
destination,
478479
target,
479480
unwind: _,

compiler/rustc_mir_transform/src/coverage/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl<'tcx> MockBlocks<'tcx> {
135135
TerminatorKind::Call {
136136
func: Operand::Copy(self.dummy_place.clone()),
137137
args: vec![],
138+
arg_spans: vec![],
138139
destination: self.dummy_place.clone(),
139140
target: Some(TEMP_BLOCK),
140141
unwind: UnwindAction::Continue,

compiler/rustc_mir_transform/src/function_item_references.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
3131
if let TerminatorKind::Call {
3232
func,
3333
args,
34+
arg_spans: _,
3435
destination: _,
3536
target: _,
3637
unwind: _,

compiler/rustc_mir_transform/src/generator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
16611661
TerminatorKind::Call {
16621662
func,
16631663
args,
1664+
arg_spans: _,
16641665
destination,
16651666
target: Some(_),
16661667
unwind: _,

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn remap_mir_for_const_eval_select<'tcx>(
153153
TerminatorKind::Call {
154154
func: Operand::Constant(box ConstOperand { ref const_, .. }),
155155
ref mut args,
156+
ref mut arg_spans,
156157
destination,
157158
target,
158159
unwind,
@@ -192,7 +193,16 @@ fn remap_mir_for_const_eval_select<'tcx>(
192193
};
193194
method(place)
194195
}).collect();
195-
terminator.kind = TerminatorKind::Call { func, args: arguments, destination, target, unwind, call_source: CallSource::Misc, fn_span };
196+
terminator.kind = TerminatorKind::Call {
197+
func,
198+
args: arguments,
199+
arg_spans: std::mem::take(arg_spans),
200+
destination,
201+
target,
202+
unwind,
203+
call_source: CallSource::Misc,
204+
fn_span,
205+
};
196206
}
197207
_ => {}
198208
}

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
99

1010
use rustc_index::{Idx, IndexVec};
1111

12-
use rustc_span::Span;
12+
use rustc_span::{Span, DUMMY_SP};
1313
use rustc_target::spec::abi::Abi;
1414

1515
use std::fmt;
@@ -524,6 +524,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
524524
TerminatorKind::Call {
525525
func,
526526
args: vec![Operand::Move(ref_loc)],
527+
arg_spans: vec![DUMMY_SP],
527528
destination: dest,
528529
target: Some(next),
529530
unwind: UnwindAction::Cleanup(cleanup),
@@ -808,12 +809,14 @@ fn build_call_shim<'tcx>(
808809
};
809810

810811
// BB #0
812+
let arg_spans = args.iter().map(|_| DUMMY_SP).collect();
811813
block(
812814
&mut blocks,
813815
statements,
814816
TerminatorKind::Call {
815817
func: callee,
816818
args,
819+
arg_spans,
817820
destination: Place::return_place(),
818821
target: Some(BasicBlock::new(1)),
819822
unwind: if let Some(Adjustment::RefMut) = rcvr_adjustment {

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
811811
};
812812

813813
match terminator.kind {
814-
mir::TerminatorKind::Call { ref func, ref args, .. } => {
814+
mir::TerminatorKind::Call {
815+
ref func, ref args, ..
816+
} => {
815817
let callee_ty = func.ty(self.body, tcx);
816818
let callee_ty = self.monomorphize(callee_ty);
817819
self.check_fn_args_move_size(callee_ty, args, location);

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
874874
mir::TerminatorKind::Call {
875875
func,
876876
args,
877+
arg_spans: _,
877878
destination,
878879
target,
879880
unwind,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,13 +3611,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
36113611
let mut prev_ty = self.resolve_vars_if_possible(
36123612
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
36133613
);
3614-
while let hir::ExprKind::MethodCall(_path_segment, rcvr_expr, _args, span) = expr.kind {
3614+
while let hir::ExprKind::MethodCall(_path_segment, rcvr_expr, _args, span) = &expr.kind {
36153615
// Point at every method call in the chain with the resulting type.
36163616
// vec![1, 2, 3].iter().map(mapper).sum<i32>()
36173617
// ^^^^^^ ^^^^^^^^^^^
36183618
expr = rcvr_expr;
36193619
let assocs_in_this_method =
3620-
self.probe_assoc_types_at_expr(&type_diffs, span, prev_ty, expr.hir_id, param_env);
3620+
self.probe_assoc_types_at_expr(&type_diffs, *span, prev_ty, expr.hir_id, param_env);
36213621
assocs.push(assocs_in_this_method);
36223622
prev_ty = self.resolve_vars_if_possible(
36233623
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ fn check_terminator<'tcx>(
311311
TerminatorKind::Call {
312312
func,
313313
args,
314+
arg_spans: _,
314315
call_source: _,
315316
destination: _,
316317
target: _,

0 commit comments

Comments
 (0)