@@ -1005,6 +1005,10 @@ fn get_assignment<'tcx>(e: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, &'tcx
10051005 }
10061006}
10071007
1008+ /// Get assignments from the given block.
1009+ /// The returned iterator yields `None` if no assignment expressions are there,
1010+ /// filtering out the increments of the given whitelisted loop counters;
1011+ /// because its job is to make sure there's nothing other than assignments and the increments.
10081012fn get_assignments < ' a : ' c , ' tcx : ' c , ' c > (
10091013 cx : & ' a LateContext < ' tcx > ,
10101014 Block { stmts, expr, .. } : & ' tcx Block < ' tcx > ,
@@ -1021,7 +1025,8 @@ fn get_assignments<'a: 'c, 'tcx: 'c, 'c>(
10211025 if let ExprKind :: AssignOp ( _, place, _) = e. kind {
10221026 !loop_counters
10231027 . iter ( )
1024- // skip StartKind::Range
1028+ // skip the first item which should be `StartKind::Range`
1029+ // this makes it possible to use the slice with `StartKind::Range` in the same iterator loop.
10251030 . skip ( 1 )
10261031 . any ( |counter| same_var ( cx, place, counter. id ) )
10271032 } else {
@@ -1191,11 +1196,11 @@ fn detect_manual_memcpy<'tcx>(
11911196 iter_b = Some ( get_assignment ( body) ) ;
11921197 }
11931198
1194- // The only statements in the for loops can be indexed assignments from
1195- // indexed retrievals.
11961199 let assignments = iter_a. into_iter ( ) . flatten ( ) . chain ( iter_b. into_iter ( ) ) ;
11971200
11981201 let big_sugg = assignments
1202+ // The only statements in the for loops can be indexed assignments from
1203+ // indexed retrievals (except increments of loop counters).
11991204 . map ( |o| {
12001205 o. and_then ( |( lhs, rhs) | {
12011206 let rhs = fetch_cloned_expr ( rhs) ;
0 commit comments