@@ -359,7 +359,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
359359 }
360360
361361 // Unpack arguments tuple for closures
362- let args = if fn_sig. abi == Abi :: RustCall {
362+ let mut args = if fn_sig. abi == Abi :: RustCall {
363363 assert_eq ! ( args. len( ) , 2 , "rust-call abi requires two arguments" ) ;
364364 let self_arg = codegen_operand ( fx, & args[ 0 ] ) ;
365365 let pack_arg = codegen_operand ( fx, & args[ 1 ] ) ;
@@ -379,6 +379,15 @@ pub(crate) fn codegen_terminator_call<'tcx>(
379379 args. iter ( ) . map ( |arg| codegen_operand ( fx, arg) ) . collect :: < Vec < _ > > ( )
380380 } ;
381381
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+
382391 enum CallTarget {
383392 Direct ( FuncRef ) ,
384393 Indirect ( SigRef , Value ) ,
@@ -425,8 +434,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
425434
426435 let ret_place = destination. map ( |( place, _) | place) ;
427436 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
430438 . into_iter ( )
431439 . chain ( first_arg_override. into_iter ( ) )
432440 . chain (
@@ -436,19 +444,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
436444 . map ( |( i, arg) | adjust_arg_for_abi ( fx, arg, & fn_abi. args [ i] ) . into_iter ( ) )
437445 . flatten ( ) ,
438446 )
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 > > ( ) ;
452448
453449 let call_inst = match func_ref {
454450 CallTarget :: Direct ( func_ref) => fx. bcx . ins ( ) . call ( func_ref, & call_args) ,
0 commit comments