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