@@ -89,25 +89,6 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
89
89
_ => None ,
90
90
} ;
91
91
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
-
111
92
let safety = match fn_sig. unsafety {
112
93
hir:: Unsafety :: Normal => Safety :: Safe ,
113
94
hir:: Unsafety :: Unsafe => Safety :: FnUnsafe ,
@@ -161,7 +142,7 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
161
142
} ) ;
162
143
163
144
let arguments = implicit_argument. into_iter ( )
164
- . chain ( location_argument )
145
+ . chain ( track_caller_argument ( tcx , def_id ) )
165
146
. chain ( explicit_arguments) ;
166
147
167
148
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<'_> {
206
187
} )
207
188
}
208
189
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
+
209
201
///////////////////////////////////////////////////////////////////////////
210
202
// BuildMir -- walks a crate, looking for fn items and methods to build MIR from
211
203
0 commit comments