@@ -5,7 +5,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug
5
5
use clippy_utils:: is_from_proc_macro;
6
6
use clippy_utils:: macros:: { is_panic, macro_backtrace} ;
7
7
use clippy_utils:: source:: { first_line_of_span, is_present_in_source, snippet_opt, without_block_comments} ;
8
- use if_chain:: if_chain;
9
8
use rustc_ast:: token:: { Token , TokenKind } ;
10
9
use rustc_ast:: tokenstream:: TokenTree ;
11
10
use rustc_ast:: {
@@ -471,13 +470,11 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
471
470
return ;
472
471
}
473
472
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) ;
481
478
}
482
479
}
483
480
}
@@ -580,15 +577,13 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
580
577
581
578
/// Returns the lint name if it is clippy lint.
582
579
fn 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) ;
592
587
}
593
588
None
594
589
}
@@ -857,40 +852,38 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
857
852
}
858
853
859
854
fn 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 )
862
856
// 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
866
860
// 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)
869
863
// 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) )
872
866
|| skip_item
873
867
. path
874
868
. segments
875
869
. last ( )
876
870
. expect ( "empty path in attribute" )
877
871
. ident
878
872
. name
879
- == sym:: skip;
873
+ == sym:: skip)
880
874
// Only lint outer attributes, because custom inner attributes are unstable
881
875
// 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
+ ) ;
894
887
}
895
888
}
896
889
@@ -990,12 +983,10 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
990
983
mismatched. extend ( find_mismatched_target_os ( list) ) ;
991
984
} ,
992
985
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 ) ) ;
999
990
}
1000
991
} ,
1001
992
MetaItemKind :: NameValue ( ..) => { } ,
@@ -1006,30 +997,28 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
1006
997
mismatched
1007
998
}
1008
999
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 ;
1030
1019
}
1031
- } ) ;
1032
- }
1020
+ }
1021
+ } ) ;
1033
1022
}
1034
1023
}
1035
1024
0 commit comments