@@ -200,6 +200,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
200
200
Attribute :: Parsed ( AttributeKind :: NoMangle ( attr_span) ) => {
201
201
self . check_no_mangle ( hir_id, * attr_span, span, target)
202
202
}
203
+ Attribute :: Parsed ( AttributeKind :: Used { span : attr_span, .. } ) => {
204
+ self . check_used ( * attr_span, target, span) ;
205
+ }
203
206
Attribute :: Unparsed ( attr_item) => {
204
207
style = Some ( attr_item. style ) ;
205
208
match attr. path ( ) . as_slice ( ) {
@@ -333,7 +336,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
333
336
| sym:: cfi_encoding // FIXME(cfi_encoding)
334
337
| sym:: pointee // FIXME(derive_coerce_pointee)
335
338
| sym:: omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
336
- | sym:: used // handled elsewhere to restrict to static items
337
339
| sym:: instruction_set // broken on stable!!!
338
340
| sym:: windows_subsystem // broken on stable!!!
339
341
| sym:: patchable_function_entry // FIXME(patchable_function_entry)
@@ -403,7 +405,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
403
405
}
404
406
405
407
self . check_repr ( attrs, span, target, item, hir_id) ;
406
- self . check_used ( attrs, target, span) ;
407
408
self . check_rustc_force_inline ( hir_id, attrs, span, target) ;
408
409
self . check_mix_no_mangle_export ( hir_id, attrs) ;
409
410
}
@@ -2107,44 +2108,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2107
2108
}
2108
2109
}
2109
2110
2110
- fn check_used ( & self , attrs : & [ Attribute ] , target : Target , target_span : Span ) {
2111
- let mut used_linker_span = None ;
2112
- let mut used_compiler_span = None ;
2113
- for attr in attrs. iter ( ) . filter ( |attr| attr. has_name ( sym:: used) ) {
2114
- if target != Target :: Static {
2115
- self . dcx ( ) . emit_err ( errors:: UsedStatic {
2116
- attr_span : attr. span ( ) ,
2117
- span : target_span,
2118
- target : target. name ( ) ,
2119
- } ) ;
2120
- }
2121
- let inner = attr. meta_item_list ( ) ;
2122
- match inner. as_deref ( ) {
2123
- Some ( [ item] ) if item. has_name ( sym:: linker) => {
2124
- if used_linker_span. is_none ( ) {
2125
- used_linker_span = Some ( attr. span ( ) ) ;
2126
- }
2127
- }
2128
- Some ( [ item] ) if item. has_name ( sym:: compiler) => {
2129
- if used_compiler_span. is_none ( ) {
2130
- used_compiler_span = Some ( attr. span ( ) ) ;
2131
- }
2132
- }
2133
- Some ( _) => {
2134
- // This error case is handled in rustc_hir_analysis::collect.
2135
- }
2136
- None => {
2137
- // Default case (compiler) when arg isn't defined.
2138
- if used_compiler_span. is_none ( ) {
2139
- used_compiler_span = Some ( attr. span ( ) ) ;
2140
- }
2141
- }
2142
- }
2143
- }
2144
- if let ( Some ( linker_span) , Some ( compiler_span) ) = ( used_linker_span, used_compiler_span) {
2145
- self . tcx
2146
- . dcx ( )
2147
- . emit_err ( errors:: UsedCompilerLinker { spans : vec ! [ linker_span, compiler_span] } ) ;
2111
+ fn check_used ( & self , attr_span : Span , target : Target , target_span : Span ) {
2112
+ if target != Target :: Static {
2113
+ self . dcx ( ) . emit_err ( errors:: UsedStatic {
2114
+ attr_span,
2115
+ span : target_span,
2116
+ target : target. name ( ) ,
2117
+ } ) ;
2148
2118
}
2149
2119
}
2150
2120
0 commit comments