@@ -278,6 +278,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
278278 | AttributeKind :: ObjcClass { .. }
279279 | AttributeKind :: ObjcSelector { .. }
280280 | AttributeKind :: RustcCoherenceIsCore ( ..)
281+ | AttributeKind :: Feature ( ..)
281282 ) => { /* do nothing */ }
282283 Attribute :: Unparsed ( attr_item) => {
283284 style = Some ( attr_item. style ) ;
@@ -1895,75 +1896,82 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18951896 fn check_unused_attribute ( & self , hir_id : HirId , attr : & Attribute , style : Option < AttrStyle > ) {
18961897 // Warn on useless empty attributes.
18971898 // FIXME(jdonszelmann): this lint should be moved to attribute parsing, see `AcceptContext::warn_empty_attribute`
1898- let note = if attr. has_any_name ( & [
1899- sym:: allow,
1900- sym:: expect,
1901- sym:: warn,
1902- sym:: deny,
1903- sym:: forbid,
1904- sym:: feature,
1905- ] ) && attr. meta_item_list ( ) . is_some_and ( |list| list. is_empty ( ) )
1906- {
1907- errors:: UnusedNote :: EmptyList { name : attr. name ( ) . unwrap ( ) }
1908- } else if attr. has_any_name ( & [ sym:: allow, sym:: warn, sym:: deny, sym:: forbid, sym:: expect] )
1909- && let Some ( meta) = attr. meta_item_list ( )
1910- && let [ meta] = meta. as_slice ( )
1911- && let Some ( item) = meta. meta_item ( )
1912- && let MetaItemKind :: NameValue ( _) = & item. kind
1913- && item. path == sym:: reason
1914- {
1915- errors:: UnusedNote :: NoLints { name : attr. name ( ) . unwrap ( ) }
1916- } else if attr. has_any_name ( & [ sym:: allow, sym:: warn, sym:: deny, sym:: forbid, sym:: expect] )
1917- && let Some ( meta) = attr. meta_item_list ( )
1918- && meta. iter ( ) . any ( |meta| {
1919- meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
1920- } )
1921- {
1922- if hir_id != CRATE_HIR_ID {
1923- match style {
1924- Some ( ast:: AttrStyle :: Outer ) => {
1925- let attr_span = attr. span ( ) ;
1926- let bang_position = self
1927- . tcx
1928- . sess
1929- . source_map ( )
1930- . span_until_char ( attr_span, '[' )
1931- . shrink_to_hi ( ) ;
1932-
1933- self . tcx . emit_node_span_lint (
1899+ let note =
1900+ if attr. has_any_name ( & [ sym:: allow, sym:: expect, sym:: warn, sym:: deny, sym:: forbid] )
1901+ && attr. meta_item_list ( ) . is_some_and ( |list| list. is_empty ( ) )
1902+ {
1903+ errors:: UnusedNote :: EmptyList { name : attr. name ( ) . unwrap ( ) }
1904+ } else if attr. has_any_name ( & [
1905+ sym:: allow,
1906+ sym:: warn,
1907+ sym:: deny,
1908+ sym:: forbid,
1909+ sym:: expect,
1910+ ] ) && let Some ( meta) = attr. meta_item_list ( )
1911+ && let [ meta] = meta. as_slice ( )
1912+ && let Some ( item) = meta. meta_item ( )
1913+ && let MetaItemKind :: NameValue ( _) = & item. kind
1914+ && item. path == sym:: reason
1915+ {
1916+ errors:: UnusedNote :: NoLints { name : attr. name ( ) . unwrap ( ) }
1917+ } else if attr. has_any_name ( & [
1918+ sym:: allow,
1919+ sym:: warn,
1920+ sym:: deny,
1921+ sym:: forbid,
1922+ sym:: expect,
1923+ ] ) && let Some ( meta) = attr. meta_item_list ( )
1924+ && meta. iter ( ) . any ( |meta| {
1925+ meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
1926+ } )
1927+ {
1928+ if hir_id != CRATE_HIR_ID {
1929+ match style {
1930+ Some ( ast:: AttrStyle :: Outer ) => {
1931+ let attr_span = attr. span ( ) ;
1932+ let bang_position = self
1933+ . tcx
1934+ . sess
1935+ . source_map ( )
1936+ . span_until_char ( attr_span, '[' )
1937+ . shrink_to_hi ( ) ;
1938+
1939+ self . tcx . emit_node_span_lint (
1940+ UNUSED_ATTRIBUTES ,
1941+ hir_id,
1942+ attr_span,
1943+ errors:: OuterCrateLevelAttr {
1944+ suggestion : errors:: OuterCrateLevelAttrSuggestion {
1945+ bang_position,
1946+ } ,
1947+ } ,
1948+ )
1949+ }
1950+ Some ( ast:: AttrStyle :: Inner ) | None => self . tcx . emit_node_span_lint (
19341951 UNUSED_ATTRIBUTES ,
19351952 hir_id,
1936- attr_span,
1937- errors:: OuterCrateLevelAttr {
1938- suggestion : errors:: OuterCrateLevelAttrSuggestion { bang_position } ,
1939- } ,
1940- )
1941- }
1942- Some ( ast:: AttrStyle :: Inner ) | None => self . tcx . emit_node_span_lint (
1943- UNUSED_ATTRIBUTES ,
1944- hir_id,
1945- attr. span ( ) ,
1946- errors:: InnerCrateLevelAttr ,
1947- ) ,
1948- } ;
1949- return ;
1950- } else {
1951- let never_needs_link = self
1952- . tcx
1953- . crate_types ( )
1954- . iter ( )
1955- . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
1956- if never_needs_link {
1957- errors:: UnusedNote :: LinkerMessagesBinaryCrateOnly
1958- } else {
1953+ attr. span ( ) ,
1954+ errors:: InnerCrateLevelAttr ,
1955+ ) ,
1956+ } ;
19591957 return ;
1958+ } else {
1959+ let never_needs_link = self
1960+ . tcx
1961+ . crate_types ( )
1962+ . iter ( )
1963+ . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
1964+ if never_needs_link {
1965+ errors:: UnusedNote :: LinkerMessagesBinaryCrateOnly
1966+ } else {
1967+ return ;
1968+ }
19601969 }
1961- }
1962- } else if attr. has_name ( sym:: default_method_body_is_const) {
1963- errors:: UnusedNote :: DefaultMethodBodyConst
1964- } else {
1965- return ;
1966- } ;
1970+ } else if attr. has_name ( sym:: default_method_body_is_const) {
1971+ errors:: UnusedNote :: DefaultMethodBodyConst
1972+ } else {
1973+ return ;
1974+ } ;
19671975
19681976 self . tcx . emit_node_span_lint (
19691977 UNUSED_ATTRIBUTES ,
0 commit comments