@@ -5,6 +5,7 @@ use rustc_ast as ast;
55use  rustc_ast:: { InlineAsmOptions ,  InlineAsmTemplatePiece } ; 
66use  rustc_data_structures:: packed:: Pu128 ; 
77use  rustc_hir:: lang_items:: LangItem ; 
8+ use  rustc_lint_defs:: builtin:: TAIL_CALL_TRACK_CALLER ; 
89use  rustc_middle:: mir:: { self ,  AssertKind ,  InlineAsmMacro ,  SwitchTargets ,  UnwindTerminateReason } ; 
910use  rustc_middle:: ty:: layout:: { HasTyCtxt ,  LayoutOf ,  ValidityRequirement } ; 
1011use  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> {
906907                    fn_span, 
907908                ) ; 
908909
909-                 let  instance =  match  instance. def  { 
910+                 match  instance. def  { 
910911                    // We don't need AsyncDropGlueCtorShim here because it is not `noop func`, 
911912                    // it is `func returning noop future` 
912913                    ty:: InstanceKind :: DropGlue ( _,  None )  => { 
@@ -995,14 +996,35 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
995996                                        intrinsic. name, 
996997                                    ) ; 
997998                                } 
998-                                 instance
999+                                 ( Some ( instance) ,   None ) 
9991000                            } 
10001001                        } 
10011002                    } 
1002-                     _ => instance, 
1003-                 } ; 
10041003
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+                 } 
10061028            } 
10071029            ty:: FnPtr ( ..)  => ( None ,  Some ( callee. immediate ( ) ) ) , 
10081030            _ => bug ! ( "{} is not callable" ,  callee. layout. ty) , 
0 commit comments