@@ -200,6 +200,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
200200 Attribute :: Parsed ( AttributeKind :: NoMangle ( attr_span) ) => {
201201 self . check_no_mangle ( hir_id, * attr_span, span, target)
202202 }
203+ Attribute :: Parsed ( AttributeKind :: Used { span : attr_span, .. } ) => {
204+ self . check_used ( * attr_span, target, span) ;
205+ }
203206 Attribute :: Unparsed ( attr_item) => {
204207 style = Some ( attr_item. style ) ;
205208 match attr. path ( ) . as_slice ( ) {
@@ -333,7 +336,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
333336 | sym:: cfi_encoding // FIXME(cfi_encoding)
334337 | sym:: pointee // FIXME(derive_coerce_pointee)
335338 | sym:: omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
336- | sym:: used // handled elsewhere to restrict to static items
337339 | sym:: instruction_set // broken on stable!!!
338340 | sym:: windows_subsystem // broken on stable!!!
339341 | sym:: patchable_function_entry // FIXME(patchable_function_entry)
@@ -403,7 +405,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
403405 }
404406
405407 self . check_repr ( attrs, span, target, item, hir_id) ;
406- self . check_used ( attrs, target, span) ;
407408 self . check_rustc_force_inline ( hir_id, attrs, span, target) ;
408409 self . check_mix_no_mangle_export ( hir_id, attrs) ;
409410 }
@@ -2107,44 +2108,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
21072108 }
21082109 }
21092110
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+ } ) ;
21482118 }
21492119 }
21502120
0 commit comments