@@ -5,6 +5,7 @@ use rustc_ast as ast;
5
5
use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
6
6
use rustc_data_structures:: packed:: Pu128 ;
7
7
use rustc_hir:: lang_items:: LangItem ;
8
+ use rustc_lint_defs:: builtin:: TAIL_CALL_TRACK_CALLER ;
8
9
use rustc_middle:: mir:: { self , AssertKind , InlineAsmMacro , SwitchTargets , UnwindTerminateReason } ;
9
10
use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf , ValidityRequirement } ;
10
11
use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths} ;
@@ -906,7 +907,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
906
907
fn_span,
907
908
) ;
908
909
909
- let instance = match instance. def {
910
+ match instance. def {
910
911
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
911
912
// it is `func returning noop future`
912
913
ty:: InstanceKind :: DropGlue ( _, None ) => {
@@ -995,14 +996,35 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
995
996
intrinsic. name,
996
997
) ;
997
998
}
998
- instance
999
+ ( Some ( instance) , None )
999
1000
}
1000
1001
}
1001
1002
}
1002
- _ => instance,
1003
- } ;
1004
1003
1005
- ( Some ( instance) , None )
1004
+ _ if kind == CallKind :: Tail
1005
+ && instance. def . requires_caller_location ( bx. tcx ( ) ) =>
1006
+ {
1007
+ if let Some ( hir_id) =
1008
+ terminator. source_info . scope . lint_root ( & self . mir . source_scopes )
1009
+ {
1010
+ let msg = "tail calling a function marked with `#[track_caller]` has no special effect" ;
1011
+ bx. tcx ( ) . node_lint ( TAIL_CALL_TRACK_CALLER , hir_id, |d| {
1012
+ _ = d. primary_message ( msg) . span ( fn_span)
1013
+ } ) ;
1014
+ }
1015
+
1016
+ let instance = ty:: Instance :: resolve_for_fn_ptr (
1017
+ bx. tcx ( ) ,
1018
+ bx. typing_env ( ) ,
1019
+ def_id,
1020
+ generic_args,
1021
+ )
1022
+ . unwrap ( ) ;
1023
+
1024
+ ( None , Some ( bx. get_fn_addr ( instance) ) )
1025
+ }
1026
+ _ => ( Some ( instance) , None ) ,
1027
+ }
1006
1028
}
1007
1029
ty:: FnPtr ( ..) => ( None , Some ( callee. immediate ( ) ) ) ,
1008
1030
_ => bug ! ( "{} is not callable" , callee. layout. ty) ,
0 commit comments