@@ -89,25 +89,6 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
8989 _ => None ,
9090 } ;
9191
92- // if this fn has #[track_caller], it will receive an implicit argument with a location
93- let has_track_caller = tcx. codegen_fn_attrs ( def_id) . flags
94- . contains ( hir:: CodegenFnAttrFlags :: TRACK_CALLER ) ;
95- let location_argument = if has_track_caller {
96- #[ cfg( not( bootstrap) ) ]
97- {
98- use rustc:: middle:: lang_items:: PanicLocationLangItem ;
99- let panic_loc_item = tcx. require_lang_item ( PanicLocationLangItem , None ) ;
100- let panic_loc_ty = tcx. type_of ( panic_loc_item) ;
101- Some ( ArgInfo ( panic_loc_ty, None , None , None ) )
102- }
103- #[ cfg( bootstrap) ]
104- {
105- bug ! ( "#[track_caller] can't be used during a bootstrap build (yet)." ) ;
106- }
107- } else {
108- None
109- } ;
110-
11192 let safety = match fn_sig. unsafety {
11293 hir:: Unsafety :: Normal => Safety :: Safe ,
11394 hir:: Unsafety :: Unsafe => Safety :: FnUnsafe ,
@@ -161,7 +142,7 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
161142 } ) ;
162143
163144 let arguments = implicit_argument. into_iter ( )
164- . chain ( location_argument )
145+ . chain ( track_caller_argument ( tcx , def_id ) )
165146 . chain ( explicit_arguments) ;
166147
167148 let ( yield_ty, return_ty) = if body. generator_kind . is_some ( ) {
@@ -206,6 +187,17 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
206187 } )
207188}
208189
190+ /// Returns the appropriate `ArgInfo` if the provided function has #[track_caller].
191+ fn track_caller_argument ( tcx : TyCtxt < ' _ > , fn_def_id : DefId ) -> Option < ArgInfo < ' _ > > {
192+ let codegen_flags = tcx. codegen_fn_attrs ( fn_def_id) . flags ;
193+ let has_track_caller = codegen_flags. contains ( hir:: CodegenFnAttrFlags :: TRACK_CALLER ) ;
194+ if has_track_caller {
195+ Some ( ArgInfo ( ty:: Instance :: track_caller_ty ( tcx) , None , None , None ) )
196+ } else {
197+ None
198+ }
199+ }
200+
209201///////////////////////////////////////////////////////////////////////////
210202// BuildMir -- walks a crate, looking for fn items and methods to build MIR from
211203
0 commit comments