@@ -163,6 +163,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
163
163
Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
164
164
self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
165
165
}
166
+ Attribute :: Parsed ( AttributeKind :: Used { span : attr_span, .. } ) => {
167
+ self . check_used ( * attr_span, target, span) ;
168
+ }
166
169
Attribute :: Unparsed ( _) => {
167
170
match attr. path ( ) . as_slice ( ) {
168
171
[ sym:: diagnostic, sym:: do_not_recommend, ..] => {
@@ -303,7 +306,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303
306
| sym:: cfi_encoding // FIXME(cfi_encoding)
304
307
| sym:: pointee // FIXME(derive_coerce_pointee)
305
308
| sym:: omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
306
- | sym:: used // handled elsewhere to restrict to static items
307
309
| sym:: instruction_set // broken on stable!!!
308
310
| sym:: windows_subsystem // broken on stable!!!
309
311
| sym:: patchable_function_entry // FIXME(patchable_function_entry)
@@ -373,7 +375,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
373
375
}
374
376
375
377
self . check_repr ( attrs, span, target, item, hir_id) ;
376
- self . check_used ( attrs, target, span) ;
377
378
self . check_rustc_force_inline ( hir_id, attrs, span, target) ;
378
379
}
379
380
@@ -2189,44 +2190,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2189
2190
}
2190
2191
}
2191
2192
2192
- fn check_used ( & self , attrs : & [ Attribute ] , target : Target , target_span : Span ) {
2193
- let mut used_linker_span = None ;
2194
- let mut used_compiler_span = None ;
2195
- for attr in attrs. iter ( ) . filter ( |attr| attr. has_name ( sym:: used) ) {
2196
- if target != Target :: Static {
2197
- self . dcx ( ) . emit_err ( errors:: UsedStatic {
2198
- attr_span : attr. span ( ) ,
2199
- span : target_span,
2200
- target : target. name ( ) ,
2201
- } ) ;
2202
- }
2203
- let inner = attr. meta_item_list ( ) ;
2204
- match inner. as_deref ( ) {
2205
- Some ( [ item] ) if item. has_name ( sym:: linker) => {
2206
- if used_linker_span. is_none ( ) {
2207
- used_linker_span = Some ( attr. span ( ) ) ;
2208
- }
2209
- }
2210
- Some ( [ item] ) if item. has_name ( sym:: compiler) => {
2211
- if used_compiler_span. is_none ( ) {
2212
- used_compiler_span = Some ( attr. span ( ) ) ;
2213
- }
2214
- }
2215
- Some ( _) => {
2216
- // This error case is handled in rustc_hir_analysis::collect.
2217
- }
2218
- None => {
2219
- // Default case (compiler) when arg isn't defined.
2220
- if used_compiler_span. is_none ( ) {
2221
- used_compiler_span = Some ( attr. span ( ) ) ;
2222
- }
2223
- }
2224
- }
2225
- }
2226
- if let ( Some ( linker_span) , Some ( compiler_span) ) = ( used_linker_span, used_compiler_span) {
2227
- self . tcx
2228
- . dcx ( )
2229
- . emit_err ( errors:: UsedCompilerLinker { spans : vec ! [ linker_span, compiler_span] } ) ;
2193
+ fn check_used ( & self , attr_span : Span , target : Target , target_span : Span ) {
2194
+ if target != Target :: Static {
2195
+ self . dcx ( ) . emit_err ( errors:: UsedStatic {
2196
+ attr_span,
2197
+ span : target_span,
2198
+ target : target. name ( ) ,
2199
+ } ) ;
2230
2200
}
2231
2201
}
2232
2202
0 commit comments