@@ -5,7 +5,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug
55use clippy_utils:: is_from_proc_macro;
66use clippy_utils:: macros:: { is_panic, macro_backtrace} ;
77use clippy_utils:: source:: { first_line_of_span, is_present_in_source, snippet_opt, without_block_comments} ;
8- use if_chain:: if_chain;
98use rustc_ast:: token:: { Token , TokenKind } ;
109use rustc_ast:: tokenstream:: TokenTree ;
1110use rustc_ast:: {
@@ -471,13 +470,11 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
471470 return ;
472471 }
473472 for item in items {
474- if_chain ! {
475- if let NestedMetaItem :: MetaItem ( mi) = & item;
476- if let MetaItemKind :: NameValue ( lit) = & mi. kind;
477- if mi. has_name( sym:: since) ;
478- then {
479- check_semver( cx, item. span( ) , lit) ;
480- }
473+ if let NestedMetaItem :: MetaItem ( mi) = & item
474+ && let MetaItemKind :: NameValue ( lit) = & mi. kind
475+ && mi. has_name ( sym:: since)
476+ {
477+ check_semver ( cx, item. span ( ) , lit) ;
481478 }
482479 }
483480 }
@@ -580,15 +577,13 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
580577
581578/// Returns the lint name if it is clippy lint.
582579fn extract_clippy_lint ( lint : & NestedMetaItem ) -> Option < Symbol > {
583- if_chain ! {
584- if let Some ( meta_item) = lint. meta_item( ) ;
585- if meta_item. path. segments. len( ) > 1 ;
586- if let tool_name = meta_item. path. segments[ 0 ] . ident;
587- if tool_name. name == sym:: clippy;
588- then {
589- let lint_name = meta_item. path. segments. last( ) . unwrap( ) . ident. name;
590- return Some ( lint_name) ;
591- }
580+ if let Some ( meta_item) = lint. meta_item ( )
581+ && meta_item. path . segments . len ( ) > 1
582+ && let tool_name = meta_item. path . segments [ 0 ] . ident
583+ && tool_name. name == sym:: clippy
584+ {
585+ let lint_name = meta_item. path . segments . last ( ) . unwrap ( ) . ident . name ;
586+ return Some ( lint_name) ;
592587 }
593588 None
594589}
@@ -857,40 +852,38 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
857852}
858853
859854fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute , msrv : & Msrv ) {
860- if_chain ! {
861- if msrv. meets( msrvs:: TOOL_ATTRIBUTES ) ;
855+ if msrv. meets ( msrvs:: TOOL_ATTRIBUTES )
862856 // check cfg_attr
863- if attr. has_name( sym:: cfg_attr) ;
864- if let Some ( items) = attr. meta_item_list( ) ;
865- if items. len( ) == 2 ;
857+ && attr. has_name ( sym:: cfg_attr)
858+ && let Some ( items) = attr. meta_item_list ( )
859+ && items. len ( ) == 2
866860 // check for `rustfmt`
867- if let Some ( feature_item) = items[ 0 ] . meta_item( ) ;
868- if feature_item. has_name( sym:: rustfmt) ;
861+ && let Some ( feature_item) = items[ 0 ] . meta_item ( )
862+ && feature_item. has_name ( sym:: rustfmt)
869863 // check for `rustfmt_skip` and `rustfmt::skip`
870- if let Some ( skip_item) = & items[ 1 ] . meta_item( ) ;
871- if skip_item. has_name( sym!( rustfmt_skip) )
864+ && let Some ( skip_item) = & items[ 1 ] . meta_item ( )
865+ && ( skip_item. has_name ( sym ! ( rustfmt_skip) )
872866 || skip_item
873867 . path
874868 . segments
875869 . last ( )
876870 . expect ( "empty path in attribute" )
877871 . ident
878872 . name
879- == sym:: skip;
873+ == sym:: skip)
880874 // Only lint outer attributes, because custom inner attributes are unstable
881875 // Tracking issue: https://github.com/rust-lang/rust/issues/54726
882- if attr. style == AttrStyle :: Outer ;
883- then {
884- span_lint_and_sugg(
885- cx,
886- DEPRECATED_CFG_ATTR ,
887- attr. span,
888- "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes" ,
889- "use" ,
890- "#[rustfmt::skip]" . to_string( ) ,
891- Applicability :: MachineApplicable ,
892- ) ;
893- }
876+ && attr. style == AttrStyle :: Outer
877+ {
878+ span_lint_and_sugg (
879+ cx,
880+ DEPRECATED_CFG_ATTR ,
881+ attr. span ,
882+ "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes" ,
883+ "use" ,
884+ "#[rustfmt::skip]" . to_string ( ) ,
885+ Applicability :: MachineApplicable ,
886+ ) ;
894887 }
895888}
896889
@@ -990,12 +983,10 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
990983 mismatched. extend ( find_mismatched_target_os ( list) ) ;
991984 } ,
992985 MetaItemKind :: Word => {
993- if_chain ! {
994- if let Some ( ident) = meta. ident( ) ;
995- if let Some ( os) = find_os( ident. name. as_str( ) ) ;
996- then {
997- mismatched. push( ( os, ident. span) ) ;
998- }
986+ if let Some ( ident) = meta. ident ( )
987+ && let Some ( os) = find_os ( ident. name . as_str ( ) )
988+ {
989+ mismatched. push ( ( os, ident. span ) ) ;
999990 }
1000991 } ,
1001992 MetaItemKind :: NameValue ( ..) => { } ,
@@ -1006,30 +997,28 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
1006997 mismatched
1007998 }
1008999
1009- if_chain ! {
1010- if attr. has_name( sym:: cfg) ;
1011- if let Some ( list) = attr. meta_item_list( ) ;
1012- let mismatched = find_mismatched_target_os( & list) ;
1013- if !mismatched. is_empty( ) ;
1014- then {
1015- let mess = "operating system used in target family position" ;
1016-
1017- span_lint_and_then( cx, MISMATCHED_TARGET_OS , attr. span, mess, |diag| {
1018- // Avoid showing the unix suggestion multiple times in case
1019- // we have more than one mismatch for unix-like systems
1020- let mut unix_suggested = false ;
1021-
1022- for ( os, span) in mismatched {
1023- let sugg = format!( "target_os = \" {os}\" " ) ;
1024- diag. span_suggestion( span, "try" , sugg, Applicability :: MaybeIncorrect ) ;
1025-
1026- if !unix_suggested && is_unix( os) {
1027- diag. help( "did you mean `unix`?" ) ;
1028- unix_suggested = true ;
1029- }
1000+ if attr. has_name ( sym:: cfg)
1001+ && let Some ( list) = attr. meta_item_list ( )
1002+ && let mismatched = find_mismatched_target_os ( & list)
1003+ && !mismatched. is_empty ( )
1004+ {
1005+ let mess = "operating system used in target family position" ;
1006+
1007+ span_lint_and_then ( cx, MISMATCHED_TARGET_OS , attr. span , mess, |diag| {
1008+ // Avoid showing the unix suggestion multiple times in case
1009+ // we have more than one mismatch for unix-like systems
1010+ let mut unix_suggested = false ;
1011+
1012+ for ( os, span) in mismatched {
1013+ let sugg = format ! ( "target_os = \" {os}\" " ) ;
1014+ diag. span_suggestion ( span, "try" , sugg, Applicability :: MaybeIncorrect ) ;
1015+
1016+ if !unix_suggested && is_unix ( os) {
1017+ diag. help ( "did you mean `unix`?" ) ;
1018+ unix_suggested = true ;
10301019 }
1031- } ) ;
1032- }
1020+ }
1021+ } ) ;
10331022 }
10341023}
10351024
0 commit comments