@@ -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 > (
@@ -2315,7 +2305,7 @@ struct IncrementVisitor<'a, 'tcx> {
2315
2305
}
2316
2306
2317
2307
impl < ' a , ' tcx > IncrementVisitor < ' a , ' tcx > {
2318
- fn new ( cx : & ' a LateContext < ' a , ' tcx > ) -> Self {
2308
+ fn new ( cx : & ' a LateContext < ' tcx > ) -> Self {
2319
2309
Self {
2320
2310
cx,
2321
2311
states : FxHashMap :: default ( ) ,
@@ -2396,7 +2386,10 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
2396
2386
enum InitializeVisitorState < ' hir > {
2397
2387
Initial , // Not examined yet
2398
2388
Declared ( Symbol ) , // Declared but not (yet) initialized
2399
- Initialized { name : Symbol , initializer : & ' hir Expr < ' hir > } ,
2389
+ Initialized {
2390
+ name : Symbol ,
2391
+ initializer : & ' hir Expr < ' hir > ,
2392
+ } ,
2400
2393
DontWarn ,
2401
2394
}
2402
2395
@@ -2412,7 +2405,7 @@ struct InitializeVisitor<'a, 'tcx> {
2412
2405
}
2413
2406
2414
2407
impl < ' a , ' tcx > InitializeVisitor < ' a , ' tcx > {
2415
- fn new ( cx : & ' a LateContext < ' a , ' tcx > , end_expr : & ' tcx Expr < ' tcx > , var_id : HirId ) -> Self {
2408
+ fn new ( cx : & ' a LateContext < ' tcx > , end_expr : & ' tcx Expr < ' tcx > , var_id : HirId ) -> Self {
2416
2409
Self {
2417
2410
cx,
2418
2411
end_expr,
@@ -2423,7 +2416,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
2423
2416
}
2424
2417
}
2425
2418
2426
- fn get_result ( & self ) -> Option < ( Name , & ' tcx Expr < ' tcx > ) > {
2419
+ fn get_result ( & self ) -> Option < ( Symbol , & ' tcx Expr < ' tcx > ) > {
2427
2420
if let InitializeVisitorState :: Initialized { name, initializer } = self . state {
2428
2421
Some ( ( name, initializer) )
2429
2422
} else {
@@ -2442,14 +2435,12 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
2442
2435
if local. pat. hir_id == self . var_id;
2443
2436
if let PatKind :: Binding ( .., ident, _) = local. pat. kind;
2444
2437
then {
2445
- self . state = if let Some ( ref init) = local . init {
2438
+ self . state = local . init. map_or ( InitializeVisitorState :: Declared ( ident . name ) , | init| {
2446
2439
InitializeVisitorState :: Initialized {
2447
2440
initializer: init,
2448
2441
name: ident. name,
2449
2442
}
2450
- } else {
2451
- InitializeVisitorState :: Declared ( ident. name)
2452
- }
2443
+ } )
2453
2444
}
2454
2445
}
2455
2446
walk_stmt ( self , stmt) ;
0 commit comments