@@ -95,17 +95,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
95
95
// In these cases, we bail from performing further checks that are only meaningful for
96
96
// functions (such as calling `fn_sig`, which ICEs if given a non-function). We also
97
97
// report a delayed bug, just in case `check_attr` isn't doing its job.
98
- let fn_sig = || {
98
+ let fn_sig = |attr_span | {
99
99
use DefKind :: * ;
100
100
101
101
let def_kind = tcx. def_kind ( did) ;
102
102
if let Fn | AssocFn | Variant | Ctor ( ..) = def_kind {
103
103
Some ( tcx. fn_sig ( did) )
104
104
} 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" ) ;
109
107
None
110
108
}
111
109
} ;
@@ -123,6 +121,29 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
123
121
AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
124
122
AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
125
123
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
+ }
126
147
_ => { }
127
148
}
128
149
}
@@ -205,29 +226,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
205
226
}
206
227
}
207
228
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
- }
231
229
sym:: export_name => {
232
230
if let Some ( s) = attr. value_str ( ) {
233
231
if s. as_str ( ) . contains ( '\0' ) {
0 commit comments