@@ -359,7 +359,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
359
359
}
360
360
361
361
// Unpack arguments tuple for closures
362
- let args = if fn_sig. abi == Abi :: RustCall {
362
+ let mut args = if fn_sig. abi == Abi :: RustCall {
363
363
assert_eq ! ( args. len( ) , 2 , "rust-call abi requires two arguments" ) ;
364
364
let self_arg = codegen_operand ( fx, & args[ 0 ] ) ;
365
365
let pack_arg = codegen_operand ( fx, & args[ 1 ] ) ;
@@ -379,6 +379,15 @@ pub(crate) fn codegen_terminator_call<'tcx>(
379
379
args. iter ( ) . map ( |arg| codegen_operand ( fx, arg) ) . collect :: < Vec < _ > > ( )
380
380
} ;
381
381
382
+ // Pass the caller location for `#[track_caller]`.
383
+ if instance. map ( |inst| inst. def . requires_caller_location ( fx. tcx ) ) . unwrap_or ( false ) {
384
+ let caller_location = fx. get_caller_location ( span) ;
385
+ args. push ( caller_location) ;
386
+ }
387
+
388
+ let args = args;
389
+ assert_eq ! ( fn_abi. args. len( ) , args. len( ) ) ;
390
+
382
391
enum CallTarget {
383
392
Direct ( FuncRef ) ,
384
393
Indirect ( SigRef , Value ) ,
@@ -425,8 +434,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
425
434
426
435
let ret_place = destination. map ( |( place, _) | place) ;
427
436
self :: returning:: codegen_with_call_return_arg ( fx, & fn_abi. ret , ret_place, |fx, return_ptr| {
428
- let regular_args_count = args. len ( ) ;
429
- let mut call_args: Vec < Value > = return_ptr
437
+ let call_args = return_ptr
430
438
. into_iter ( )
431
439
. chain ( first_arg_override. into_iter ( ) )
432
440
. chain (
@@ -436,19 +444,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
436
444
. map ( |( i, arg) | adjust_arg_for_abi ( fx, arg, & fn_abi. args [ i] ) . into_iter ( ) )
437
445
. flatten ( ) ,
438
446
)
439
- . collect :: < Vec < _ > > ( ) ;
440
-
441
- if instance. map ( |inst| inst. def . requires_caller_location ( fx. tcx ) ) . unwrap_or ( false ) {
442
- // Pass the caller location for `#[track_caller]`.
443
- let caller_location = fx. get_caller_location ( span) ;
444
- call_args. extend (
445
- adjust_arg_for_abi ( fx, caller_location, & fn_abi. args [ regular_args_count] )
446
- . into_iter ( ) ,
447
- ) ;
448
- assert_eq ! ( fn_abi. args. len( ) , regular_args_count + 1 ) ;
449
- } else {
450
- assert_eq ! ( fn_abi. args. len( ) , regular_args_count) ;
451
- }
447
+ . collect :: < Vec < Value > > ( ) ;
452
448
453
449
let call_inst = match func_ref {
454
450
CallTarget :: Direct ( func_ref) => fx. bcx . ins ( ) . call ( func_ref, & call_args) ,
0 commit comments