@@ -846,7 +846,7 @@ impl<'a> MinifyingSugg<'a> {
846
846
s. as_ref ( )
847
847
}
848
848
849
- fn hir ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > , default : & ' a str ) -> Self {
849
+ fn hir ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , default : & ' a str ) -> Self {
850
850
Self ( sugg:: Sugg :: hir ( cx, expr, default) )
851
851
}
852
852
@@ -947,11 +947,7 @@ fn get_details_from_idx<'tcx>(
947
947
idx : & Expr < ' _ > ,
948
948
starts : & [ Start < ' tcx > ] ,
949
949
) -> Option < ( StartKind < ' tcx > , Offset ) > {
950
- fn get_start < ' tcx > (
951
- cx : & LateContext < ' tcx > ,
952
- e : & Expr < ' _ > ,
953
- starts : & [ Start < ' tcx > ] ,
954
- ) -> Option < StartKind < ' tcx > > {
950
+ fn get_start < ' tcx > ( cx : & LateContext < ' tcx > , e : & Expr < ' _ > , starts : & [ Start < ' tcx > ] ) -> Option < StartKind < ' tcx > > {
955
951
starts. iter ( ) . find_map ( |start| {
956
952
if same_var ( cx, e, start. id ) {
957
953
Some ( start. kind )
@@ -982,13 +978,9 @@ fn get_details_from_idx<'tcx>(
982
978
match idx. kind {
983
979
ExprKind :: Binary ( op, lhs, rhs) => match op. node {
984
980
BinOpKind :: Add => {
985
- let offset_opt = if let Some ( s) = get_start ( cx, lhs, starts) {
986
- get_offset ( cx, rhs, starts) . map ( |o| ( s, o) )
987
- } else if let Some ( s) = get_start ( cx, rhs, starts) {
988
- get_offset ( cx, lhs, starts) . map ( |o| ( s, o) )
989
- } else {
990
- None
991
- } ;
981
+ let offset_opt = get_start ( cx, lhs, starts)
982
+ . and_then ( |s| get_offset ( cx, rhs, starts) . map ( |o| ( s, o) ) )
983
+ . or_else ( || get_start ( cx, rhs, starts) . and_then ( |s| get_offset ( cx, lhs, starts) . map ( |o| ( s, o) ) ) ) ;
992
984
993
985
offset_opt. map ( |( s, o) | ( s, Offset :: positive ( o) ) )
994
986
} ,
@@ -1011,7 +1003,7 @@ fn get_assignment<'tcx>(e: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, &'tcx
1011
1003
}
1012
1004
1013
1005
fn get_assignments < ' a : ' c , ' tcx : ' c , ' c > (
1014
- cx : & ' a LateContext < ' a , ' tcx > ,
1006
+ cx : & ' a LateContext < ' tcx > ,
1015
1007
stmts : & ' tcx [ Stmt < ' tcx > ] ,
1016
1008
expr : Option < & ' tcx Expr < ' tcx > > ,
1017
1009
loop_counters : & ' c [ Start < ' tcx > ] ,
@@ -1032,7 +1024,7 @@ fn get_assignments<'a: 'c, 'tcx: 'c, 'c>(
1032
1024
}
1033
1025
1034
1026
fn get_loop_counters < ' a , ' tcx > (
1035
- cx : & ' a LateContext < ' a , ' tcx > ,
1027
+ cx : & ' a LateContext < ' tcx > ,
1036
1028
body : & ' tcx Block < ' tcx > ,
1037
1029
expr : & ' tcx Expr < ' _ > ,
1038
1030
) -> Option < impl Iterator < Item = Start < ' tcx > > + ' a > {
@@ -1042,7 +1034,7 @@ fn get_loop_counters<'a, 'tcx>(
1042
1034
1043
1035
// For each candidate, check the parent block to see if
1044
1036
// it's initialized to zero at the start of the loop.
1045
- if let Some ( block ) = get_enclosing_block ( & cx, expr. hir_id ) {
1037
+ get_enclosing_block ( & cx, expr. hir_id ) . and_then ( |block| {
1046
1038
increment_visitor
1047
1039
. into_results ( )
1048
1040
. filter_map ( move |var_id| {
@@ -1055,9 +1047,7 @@ fn get_loop_counters<'a, 'tcx>(
1055
1047
} )
1056
1048
} )
1057
1049
. into ( )
1058
- } else {
1059
- None
1060
- }
1050
+ } )
1061
1051
}
1062
1052
1063
1053
fn build_manual_memcpy_suggestion < ' tcx > (
@@ -2267,7 +2257,7 @@ struct IncrementVisitor<'a, 'tcx> {
2267
2257
}
2268
2258
2269
2259
impl < ' a , ' tcx > IncrementVisitor < ' a , ' tcx > {
2270
- fn new ( cx : & ' a LateContext < ' a , ' tcx > ) -> Self {
2260
+ fn new ( cx : & ' a LateContext < ' tcx > ) -> Self {
2271
2261
Self {
2272
2262
cx,
2273
2263
states : FxHashMap :: default ( ) ,
@@ -2344,7 +2334,10 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
2344
2334
enum InitializeVisitorState < ' hir > {
2345
2335
Initial , // Not examined yet
2346
2336
Declared ( Symbol ) , // Declared but not (yet) initialized
2347
- Initialized { name : Symbol , initializer : & ' hir Expr < ' hir > } ,
2337
+ Initialized {
2338
+ name : Symbol ,
2339
+ initializer : & ' hir Expr < ' hir > ,
2340
+ } ,
2348
2341
DontWarn ,
2349
2342
}
2350
2343
@@ -2360,7 +2353,7 @@ struct InitializeVisitor<'a, 'tcx> {
2360
2353
}
2361
2354
2362
2355
impl < ' a , ' tcx > InitializeVisitor < ' a , ' tcx > {
2363
- fn new ( cx : & ' a LateContext < ' a , ' tcx > , end_expr : & ' tcx Expr < ' tcx > , var_id : HirId ) -> Self {
2356
+ fn new ( cx : & ' a LateContext < ' tcx > , end_expr : & ' tcx Expr < ' tcx > , var_id : HirId ) -> Self {
2364
2357
Self {
2365
2358
cx,
2366
2359
end_expr,
@@ -2371,7 +2364,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
2371
2364
}
2372
2365
}
2373
2366
2374
- fn get_result ( & self ) -> Option < ( Name , & ' tcx Expr < ' tcx > ) > {
2367
+ fn get_result ( & self ) -> Option < ( Symbol , & ' tcx Expr < ' tcx > ) > {
2375
2368
if let InitializeVisitorState :: Initialized { name, initializer } = self . state {
2376
2369
Some ( ( name, initializer) )
2377
2370
} else {
@@ -2390,14 +2383,12 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
2390
2383
if local. pat. hir_id == self . var_id;
2391
2384
if let PatKind :: Binding ( .., ident, _) = local. pat. kind;
2392
2385
then {
2393
- self . state = if let Some ( ref init) = local . init {
2386
+ self . state = local . init. map_or ( InitializeVisitorState :: Declared ( ident . name ) , | init| {
2394
2387
InitializeVisitorState :: Initialized {
2395
2388
initializer: init,
2396
2389
name: ident. name,
2397
2390
}
2398
- } else {
2399
- InitializeVisitorState :: Declared ( ident. name)
2400
- }
2391
+ } )
2401
2392
}
2402
2393
}
2403
2394
walk_stmt ( self , stmt) ;
0 commit comments