@@ -846,7 +846,7 @@ impl<'a> MinifyingSugg<'a> {
846846        s. as_ref ( ) 
847847    } 
848848
849-     fn  hir ( cx :  & LateContext < ' _ ,   ' _ > ,  expr :  & Expr < ' _ > ,  default :  & ' a  str )  -> Self  { 
849+     fn  hir ( cx :  & LateContext < ' _ > ,  expr :  & Expr < ' _ > ,  default :  & ' a  str )  -> Self  { 
850850        Self ( sugg:: Sugg :: hir ( cx,  expr,  default) ) 
851851    } 
852852
@@ -947,11 +947,7 @@ fn get_details_from_idx<'tcx>(
947947    idx :  & Expr < ' _ > , 
948948    starts :  & [ Start < ' tcx > ] , 
949949)  -> 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 > >  { 
955951        starts. iter ( ) . find_map ( |start| { 
956952            if  same_var ( cx,  e,  start. id )  { 
957953                Some ( start. kind ) 
@@ -982,13 +978,9 @@ fn get_details_from_idx<'tcx>(
982978    match  idx. kind  { 
983979        ExprKind :: Binary ( op,  lhs,  rhs)  => match  op. node  { 
984980            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) ) ) ) ; 
992984
993985                offset_opt. map ( |( s,  o) | ( s,  Offset :: positive ( o) ) ) 
994986            } , 
@@ -1011,7 +1003,7 @@ fn get_assignment<'tcx>(e: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, &'tcx
10111003} 
10121004
10131005fn  get_assignments < ' a :  ' c ,  ' tcx :  ' c ,  ' c > ( 
1014-     cx :  & ' a  LateContext < ' a ,   ' tcx > , 
1006+     cx :  & ' a  LateContext < ' tcx > , 
10151007    stmts :  & ' tcx  [ Stmt < ' tcx > ] , 
10161008    expr :  Option < & ' tcx  Expr < ' tcx > > , 
10171009    loop_counters :  & ' c  [ Start < ' tcx > ] , 
@@ -1032,7 +1024,7 @@ fn get_assignments<'a: 'c, 'tcx: 'c, 'c>(
10321024} 
10331025
10341026fn  get_loop_counters < ' a ,  ' tcx > ( 
1035-     cx :  & ' a  LateContext < ' a ,   ' tcx > , 
1027+     cx :  & ' a  LateContext < ' tcx > , 
10361028    body :  & ' tcx  Block < ' tcx > , 
10371029    expr :  & ' tcx  Expr < ' _ > , 
10381030)  -> Option < impl  Iterator < Item  = Start < ' tcx > >  + ' a >  { 
@@ -1042,7 +1034,7 @@ fn get_loop_counters<'a, 'tcx>(
10421034
10431035    // For each candidate, check the parent block to see if 
10441036    // 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|  { 
10461038        increment_visitor
10471039            . into_results ( ) 
10481040            . filter_map ( move  |var_id| { 
@@ -1055,9 +1047,7 @@ fn get_loop_counters<'a, 'tcx>(
10551047                } ) 
10561048            } ) 
10571049            . into ( ) 
1058-     }  else  { 
1059-         None 
1060-     } 
1050+     } ) 
10611051} 
10621052
10631053fn  build_manual_memcpy_suggestion < ' tcx > ( 
@@ -2267,7 +2257,7 @@ struct IncrementVisitor<'a, 'tcx> {
22672257} 
22682258
22692259impl < ' a ,  ' tcx >  IncrementVisitor < ' a ,  ' tcx >  { 
2270-     fn  new ( cx :  & ' a  LateContext < ' a ,   ' tcx > )  -> Self  { 
2260+     fn  new ( cx :  & ' a  LateContext < ' tcx > )  -> Self  { 
22712261        Self  { 
22722262            cx, 
22732263            states :  FxHashMap :: default ( ) , 
@@ -2344,7 +2334,10 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
23442334enum  InitializeVisitorState < ' hir >  { 
23452335    Initial ,           // Not examined yet 
23462336    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+     } , 
23482341    DontWarn , 
23492342} 
23502343
@@ -2360,7 +2353,7 @@ struct InitializeVisitor<'a, 'tcx> {
23602353} 
23612354
23622355impl < ' 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  { 
23642357        Self  { 
23652358            cx, 
23662359            end_expr, 
@@ -2371,7 +2364,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
23712364        } 
23722365    } 
23732366
2374-     fn  get_result ( & self )  -> Option < ( Name ,  & ' tcx  Expr < ' tcx > ) >  { 
2367+     fn  get_result ( & self )  -> Option < ( Symbol ,  & ' tcx  Expr < ' tcx > ) >  { 
23752368        if  let  InitializeVisitorState :: Initialized  {  name,  initializer }  = self . state  { 
23762369            Some ( ( name,  initializer) ) 
23772370        }  else  { 
@@ -2390,14 +2383,12 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
23902383            if  local. pat. hir_id == self . var_id; 
23912384            if  let  PatKind :: Binding ( ..,  ident,  _)  = local. pat. kind; 
23922385            then { 
2393-                 self . state = if   let   Some ( ref  init)  = local . init { 
2386+                 self . state = local . init. map_or ( InitializeVisitorState :: Declared ( ident . name ) ,  | init|  { 
23942387                    InitializeVisitorState :: Initialized  { 
23952388                        initializer:  init, 
23962389                        name:  ident. name, 
23972390                    } 
2398-                 }  else { 
2399-                     InitializeVisitorState :: Declared ( ident. name) 
2400-                 } 
2391+                 } ) 
24012392            } 
24022393        } 
24032394        walk_stmt ( self ,  stmt) ; 
0 commit comments