@@ -95,17 +95,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
9595 // In these cases, we bail from performing further checks that are only meaningful for
9696 // functions (such as calling `fn_sig`, which ICEs if given a non-function). We also
9797 // report a delayed bug, just in case `check_attr` isn't doing its job.
98- let fn_sig = || {
98+ let fn_sig = |attr_span | {
9999 use DefKind :: * ;
100100
101101 let def_kind = tcx. def_kind ( did) ;
102102 if let Fn | AssocFn | Variant | Ctor ( ..) = def_kind {
103103 Some ( tcx. fn_sig ( did) )
104104 } else {
105- tcx. dcx ( ) . span_delayed_bug (
106- attr. span ( ) ,
107- "this attribute can only be applied to functions" ,
108- ) ;
105+ tcx. dcx ( )
106+ . span_delayed_bug ( attr_span, "this attribute can only be applied to functions" ) ;
109107 None
110108 }
111109 } ;
@@ -123,6 +121,29 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
123121 AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
124122 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
125123 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
124+ AttributeKind :: TrackCaller ( attr_span) => {
125+ let is_closure = tcx. is_closure_like ( did. to_def_id ( ) ) ;
126+
127+ if !is_closure
128+ && let Some ( fn_sig) = fn_sig ( * attr_span)
129+ && fn_sig. skip_binder ( ) . abi ( ) != ExternAbi :: Rust
130+ {
131+ tcx. dcx ( ) . emit_err ( errors:: RequiresRustAbi { span : * attr_span } ) ;
132+ }
133+ if is_closure
134+ && !tcx. features ( ) . closure_track_caller ( )
135+ && !attr_span. allows_unstable ( sym:: closure_track_caller)
136+ {
137+ feature_err (
138+ & tcx. sess ,
139+ sym:: closure_track_caller,
140+ * attr_span,
141+ "`#[track_caller]` on closures is currently unstable" ,
142+ )
143+ . emit ( ) ;
144+ }
145+ codegen_fn_attrs. flags |= CodegenFnAttrFlags :: TRACK_CALLER
146+ }
126147 _ => { }
127148 }
128149 }
@@ -205,29 +226,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
205226 }
206227 }
207228 sym:: thread_local => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: THREAD_LOCAL ,
208- sym:: track_caller => {
209- let is_closure = tcx. is_closure_like ( did. to_def_id ( ) ) ;
210-
211- if !is_closure
212- && let Some ( fn_sig) = fn_sig ( )
213- && fn_sig. skip_binder ( ) . abi ( ) != ExternAbi :: Rust
214- {
215- tcx. dcx ( ) . emit_err ( errors:: RequiresRustAbi { span : attr. span ( ) } ) ;
216- }
217- if is_closure
218- && !tcx. features ( ) . closure_track_caller ( )
219- && !attr. span ( ) . allows_unstable ( sym:: closure_track_caller)
220- {
221- feature_err (
222- & tcx. sess ,
223- sym:: closure_track_caller,
224- attr. span ( ) ,
225- "`#[track_caller]` on closures is currently unstable" ,
226- )
227- . emit ( ) ;
228- }
229- codegen_fn_attrs. flags |= CodegenFnAttrFlags :: TRACK_CALLER
230- }
231229 sym:: export_name => {
232230 if let Some ( s) = attr. value_str ( ) {
233231 if s. as_str ( ) . contains ( '\0' ) {
0 commit comments