@@ -61,23 +61,13 @@ impl LintPass for WhileTrue {
61
61
}
62
62
63
63
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
64
- match e. node {
65
- ast:: ExprWhile ( ref cond, _, _) => {
66
- match cond. node {
67
- ast:: ExprLit ( ref lit) => {
68
- match lit. node {
69
- ast:: LitBool ( true ) => {
70
- cx. span_lint ( WHILE_TRUE , e. span ,
71
- "denote infinite loops with loop \
72
- { ... }") ;
73
- }
74
- _ => { }
75
- }
76
- }
77
- _ => ( )
64
+ if let ast:: ExprWhile ( ref cond, _, _) = e. node {
65
+ if let ast:: ExprLit ( ref lit) = cond. node {
66
+ if let ast:: LitBool ( true ) = lit. node {
67
+ cx. span_lint ( WHILE_TRUE , e. span ,
68
+ "denote infinite loops with loop { ... }" ) ;
78
69
}
79
70
}
80
- _ => ( )
81
71
}
82
72
}
83
73
}
@@ -93,14 +83,11 @@ impl LintPass for UnusedCasts {
93
83
}
94
84
95
85
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
96
- match e. node {
97
- ast:: ExprCast ( ref expr, ref ty) => {
98
- let t_t = ast_ty_to_ty ( cx, & infer:: new_infer_ctxt ( cx. tcx ) , & * * ty) ;
99
- if ty:: expr_ty ( cx. tcx , & * * expr) == t_t {
100
- cx. span_lint ( UNUSED_TYPECASTS , ty. span , "unnecessary type cast" ) ;
101
- }
86
+ if let ast:: ExprCast ( ref expr, ref ty) = e. node {
87
+ let t_t = ast_ty_to_ty ( cx, & infer:: new_infer_ctxt ( cx. tcx ) , & * * ty) ;
88
+ if ty:: expr_ty ( cx. tcx , & * * expr) == t_t {
89
+ cx. span_lint ( UNUSED_TYPECASTS , ty. span , "unnecessary type cast" ) ;
102
90
}
103
- _ => ( )
104
91
}
105
92
}
106
93
}
@@ -540,9 +527,8 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
540
527
impl < ' a , ' tcx , ' v > Visitor < ' v > for RawPtrDerivingVisitor < ' a , ' tcx > {
541
528
fn visit_ty ( & mut self , ty : & ast:: Ty ) {
542
529
static MSG : & ' static str = "use of `#[deriving]` with a raw pointer" ;
543
- match ty. node {
544
- ast:: TyPtr ( ..) => self . cx . span_lint ( RAW_POINTER_DERIVING , ty. span , MSG ) ,
545
- _ => { }
530
+ if let ast:: TyPtr ( ..) = ty. node {
531
+ self . cx . span_lint ( RAW_POINTER_DERIVING , ty. span , MSG ) ;
546
532
}
547
533
visit:: walk_ty ( self , ty) ;
548
534
}
@@ -720,9 +706,8 @@ impl LintPass for UnusedResults {
720
706
_ => return
721
707
} ;
722
708
723
- match expr. node {
724
- ast:: ExprRet ( ..) => return ,
725
- _ => { }
709
+ if let ast:: ExprRet ( ..) = expr. node {
710
+ return ;
726
711
}
727
712
728
713
let t = ty:: expr_ty ( cx. tcx , expr) ;
@@ -733,11 +718,8 @@ impl LintPass for UnusedResults {
733
718
ty:: ty_struct( did, _) |
734
719
ty:: ty_enum( did, _) => {
735
720
if ast_util:: is_local ( did) {
736
- match cx. tcx . map . get ( did. node ) {
737
- ast_map:: NodeItem ( it) => {
738
- warned |= check_must_use ( cx, it. attrs . as_slice ( ) , s. span ) ;
739
- }
740
- _ => { }
721
+ if let ast_map:: NodeItem ( it) = cx. tcx . map . get ( did. node ) {
722
+ warned |= check_must_use ( cx, it. attrs . as_slice ( ) , s. span ) ;
741
723
}
742
724
} else {
743
725
csearch:: get_item_attrs ( & cx. sess ( ) . cstore , did, |attrs| {
@@ -969,11 +951,8 @@ impl LintPass for NonSnakeCase {
969
951
}
970
952
971
953
fn check_item ( & mut self , cx : & Context , it : & ast:: Item ) {
972
- match it. node {
973
- ast:: ItemMod ( _) => {
974
- self . check_snake_case ( cx, "module" , it. ident , it. span ) ;
975
- }
976
- _ => { }
954
+ if let ast:: ItemMod ( _) = it. node {
955
+ self . check_snake_case ( cx, "module" , it. ident , it. span ) ;
977
956
}
978
957
}
979
958
@@ -986,27 +965,18 @@ impl LintPass for NonSnakeCase {
986
965
}
987
966
988
967
fn check_pat ( & mut self , cx : & Context , p : & ast:: Pat ) {
989
- match & p. node {
990
- & ast:: PatIdent ( _, ref path1, _) => {
991
- match cx. tcx . def_map . borrow ( ) . get ( & p. id ) {
992
- Some ( & def:: DefLocal ( _) ) => {
993
- self . check_snake_case ( cx, "variable" , path1. node , p. span ) ;
994
- }
995
- _ => { }
996
- }
968
+ if let & ast:: PatIdent ( _, ref path1, _) = & p. node {
969
+ if let Some ( & def:: DefLocal ( _) ) = cx. tcx . def_map . borrow ( ) . get ( & p. id ) {
970
+ self . check_snake_case ( cx, "variable" , path1. node , p. span ) ;
997
971
}
998
- _ => { }
999
972
}
1000
973
}
1001
974
1002
975
fn check_struct_def ( & mut self , cx : & Context , s : & ast:: StructDef ,
1003
976
_: ast:: Ident , _: & ast:: Generics , _: ast:: NodeId ) {
1004
977
for sf in s. fields . iter ( ) {
1005
- match sf. node {
1006
- ast:: StructField_ { kind : ast:: NamedField ( ident, _) , .. } => {
1007
- self . check_snake_case ( cx, "structure field" , ident, sf. span ) ;
1008
- }
1009
- _ => { }
978
+ if let ast:: StructField_ { kind : ast:: NamedField ( ident, _) , .. } = sf. node {
979
+ self . check_snake_case ( cx, "structure field" , ident, sf. span ) ;
1010
980
}
1011
981
}
1012
982
}
@@ -1069,16 +1039,13 @@ pub struct UnusedParens;
1069
1039
impl UnusedParens {
1070
1040
fn check_unused_parens_core ( & self , cx : & Context , value : & ast:: Expr , msg : & str ,
1071
1041
struct_lit_needs_parens : bool ) {
1072
- match value. node {
1073
- ast:: ExprParen ( ref inner) => {
1074
- let necessary = struct_lit_needs_parens && contains_exterior_struct_lit ( & * * inner) ;
1075
- if !necessary {
1076
- cx. span_lint ( UNUSED_PARENS , value. span ,
1077
- format ! ( "unnecessary parentheses around {}" ,
1078
- msg) . as_slice ( ) )
1079
- }
1042
+ if let ast:: ExprParen ( ref inner) = value. node {
1043
+ let necessary = struct_lit_needs_parens && contains_exterior_struct_lit ( & * * inner) ;
1044
+ if !necessary {
1045
+ cx. span_lint ( UNUSED_PARENS , value. span ,
1046
+ format ! ( "unnecessary parentheses around {}" ,
1047
+ msg) . as_slice ( ) )
1080
1048
}
1081
- _ => { }
1082
1049
}
1083
1050
1084
1051
/// Expressions that syntactically contain an "exterior" struct
@@ -1201,24 +1168,21 @@ impl LintPass for NonShorthandFieldPatterns {
1201
1168
1202
1169
fn check_pat ( & mut self , cx : & Context , pat : & ast:: Pat ) {
1203
1170
let def_map = cx. tcx . def_map . borrow ( ) ;
1204
- match pat. node {
1205
- ast:: PatStruct ( _, ref v, _) => {
1206
- for fieldpat in v. iter ( )
1207
- . filter ( |fieldpat| !fieldpat. node . is_shorthand )
1208
- . filter ( |fieldpat| def_map. get ( & fieldpat. node . pat . id )
1209
- == Some ( & def:: DefLocal ( fieldpat. node . pat . id ) ) ) {
1210
- match fieldpat. node . pat . node {
1211
- ast:: PatIdent ( _, ident, None ) if ident. node . as_str ( )
1212
- == fieldpat. node . ident . as_str ( ) => {
1213
- cx. span_lint ( NON_SHORTHAND_FIELD_PATTERNS , fieldpat. span ,
1214
- format ! ( "the `{}:` in this pattern is redundant and can \
1215
- be removed", ident. node. as_str( ) ) . as_slice ( ) )
1216
- } ,
1217
- _ => { } ,
1218
- }
1171
+ if let ast:: PatStruct ( _, ref v, _) = pat. node {
1172
+ for fieldpat in v. iter ( )
1173
+ . filter ( |fieldpat| !fieldpat. node . is_shorthand )
1174
+ . filter ( |fieldpat| def_map. get ( & fieldpat. node . pat . id )
1175
+ == Some ( & def:: DefLocal ( fieldpat. node . pat . id ) ) ) {
1176
+ match fieldpat. node . pat . node {
1177
+ ast:: PatIdent ( _, ident, None ) if ident. node . as_str ( )
1178
+ == fieldpat. node . ident . as_str ( ) => {
1179
+ cx. span_lint ( NON_SHORTHAND_FIELD_PATTERNS , fieldpat. span ,
1180
+ format ! ( "the `{}:` in this pattern is redundant and can \
1181
+ be removed", ident. node. as_str( ) ) . as_slice ( ) )
1182
+ } ,
1183
+ _ => { } ,
1219
1184
}
1220
- } ,
1221
- _ => { }
1185
+ }
1222
1186
}
1223
1187
}
1224
1188
}
@@ -1313,27 +1277,18 @@ impl LintPass for UnusedMut {
1313
1277
}
1314
1278
1315
1279
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
1316
- match e. node {
1317
- ast:: ExprMatch ( _, ref arms, _) => {
1318
- for a in arms. iter ( ) {
1319
- self . check_unused_mut_pat ( cx, a. pats . as_slice ( ) )
1320
- }
1280
+ if let ast:: ExprMatch ( _, ref arms, _) = e. node {
1281
+ for a in arms. iter ( ) {
1282
+ self . check_unused_mut_pat ( cx, a. pats . as_slice ( ) )
1321
1283
}
1322
- _ => { }
1323
1284
}
1324
1285
}
1325
1286
1326
1287
fn check_stmt ( & mut self , cx : & Context , s : & ast:: Stmt ) {
1327
- match s. node {
1328
- ast:: StmtDecl ( ref d, _) => {
1329
- match d. node {
1330
- ast:: DeclLocal ( ref l) => {
1331
- self . check_unused_mut_pat ( cx, slice:: ref_slice ( & l. pat ) ) ;
1332
- } ,
1333
- _ => { }
1334
- }
1335
- } ,
1336
- _ => { }
1288
+ if let ast:: StmtDecl ( ref d, _) = s. node {
1289
+ if let ast:: DeclLocal ( ref l) = d. node {
1290
+ self . check_unused_mut_pat ( cx, slice:: ref_slice ( & l. pat ) ) ;
1291
+ }
1337
1292
}
1338
1293
}
1339
1294
@@ -1362,26 +1317,20 @@ impl LintPass for UnusedAllocation {
1362
1317
_ => return
1363
1318
}
1364
1319
1365
- match cx. tcx . adjustments . borrow ( ) . get ( & e. id ) {
1366
- Some ( adjustment) => {
1367
- match * adjustment {
1368
- ty:: AdjustDerefRef ( ty:: AutoDerefRef { ref autoref, .. } ) => {
1369
- match autoref {
1370
- & Some ( ty:: AutoPtr ( _, ast:: MutImmutable , None ) ) => {
1371
- cx. span_lint ( UNUSED_ALLOCATION , e. span ,
1372
- "unnecessary allocation, use & instead" ) ;
1373
- }
1374
- & Some ( ty:: AutoPtr ( _, ast:: MutMutable , None ) ) => {
1375
- cx. span_lint ( UNUSED_ALLOCATION , e. span ,
1376
- "unnecessary allocation, use &mut instead" ) ;
1377
- }
1378
- _ => ( )
1379
- }
1320
+ if let Some ( adjustment) = cx. tcx . adjustments . borrow ( ) . get ( & e. id ) {
1321
+ if let ty:: AdjustDerefRef ( ty:: AutoDerefRef { ref autoref, .. } ) = * adjustment {
1322
+ match autoref {
1323
+ & Some ( ty:: AutoPtr ( _, ast:: MutImmutable , None ) ) => {
1324
+ cx. span_lint ( UNUSED_ALLOCATION , e. span ,
1325
+ "unnecessary allocation, use & instead" ) ;
1380
1326
}
1381
- _ => { }
1327
+ & Some ( ty:: AutoPtr ( _, ast:: MutMutable , None ) ) => {
1328
+ cx. span_lint ( UNUSED_ALLOCATION , e. span ,
1329
+ "unnecessary allocation, use &mut instead" ) ;
1330
+ }
1331
+ _ => ( )
1382
1332
}
1383
1333
}
1384
- _ => ( )
1385
1334
}
1386
1335
}
1387
1336
}
@@ -1499,17 +1448,14 @@ impl LintPass for MissingDoc {
1499
1448
fn check_fn ( & mut self , cx : & Context ,
1500
1449
fk : visit:: FnKind , _: & ast:: FnDecl ,
1501
1450
_: & ast:: Block , _: Span , _: ast:: NodeId ) {
1502
- match fk {
1503
- visit:: FkMethod ( _, _, m) => {
1504
- // If the method is an impl for a trait, don't doc.
1505
- if method_context ( cx, m) == TraitImpl { return ; }
1506
-
1507
- // Otherwise, doc according to privacy. This will also check
1508
- // doc for default methods defined on traits.
1509
- self . check_missing_docs_attrs ( cx, Some ( m. id ) , m. attrs . as_slice ( ) ,
1510
- m. span , "a method" ) ;
1511
- }
1512
- _ => { }
1451
+ if let visit:: FkMethod ( _, _, m) = fk {
1452
+ // If the method is an impl for a trait, don't doc.
1453
+ if method_context ( cx, m) == TraitImpl { return ; }
1454
+
1455
+ // Otherwise, doc according to privacy. This will also check
1456
+ // doc for default methods defined on traits.
1457
+ self . check_missing_docs_attrs ( cx, Some ( m. id ) , m. attrs . as_slice ( ) ,
1458
+ m. span , "a method" ) ;
1513
1459
}
1514
1460
}
1515
1461
0 commit comments