@@ -163,6 +163,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
163163 Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
164164 self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
165165 }
166+ Attribute :: Parsed ( AttributeKind :: Used { span : attr_span, .. } ) => {
167+ self . check_used ( * attr_span, target, span) ;
168+ }
166169 Attribute :: Unparsed ( _) => {
167170 match attr. path ( ) . as_slice ( ) {
168171 [ sym:: diagnostic, sym:: do_not_recommend, ..] => {
@@ -303,7 +306,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303306 | sym:: cfi_encoding // FIXME(cfi_encoding)
304307 | sym:: pointee // FIXME(derive_coerce_pointee)
305308 | sym:: omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
306- | sym:: used // handled elsewhere to restrict to static items
307309 | sym:: instruction_set // broken on stable!!!
308310 | sym:: windows_subsystem // broken on stable!!!
309311 | sym:: patchable_function_entry // FIXME(patchable_function_entry)
@@ -373,7 +375,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
373375 }
374376
375377 self . check_repr ( attrs, span, target, item, hir_id) ;
376- self . check_used ( attrs, target, span) ;
377378 self . check_rustc_force_inline ( hir_id, attrs, span, target) ;
378379 }
379380
@@ -2189,44 +2190,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
21892190 }
21902191 }
21912192
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+ } ) ;
22302200 }
22312201 }
22322202
0 commit comments