@@ -1005,6 +1005,10 @@ fn get_assignment<'tcx>(e: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, &'tcx
1005
1005
}
1006
1006
}
1007
1007
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.
1008
1012
fn get_assignments < ' a : ' c , ' tcx : ' c , ' c > (
1009
1013
cx : & ' a LateContext < ' tcx > ,
1010
1014
Block { stmts, expr, .. } : & ' tcx Block < ' tcx > ,
@@ -1021,7 +1025,8 @@ fn get_assignments<'a: 'c, 'tcx: 'c, 'c>(
1021
1025
if let ExprKind :: AssignOp ( _, place, _) = e. kind {
1022
1026
!loop_counters
1023
1027
. 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.
1025
1030
. skip ( 1 )
1026
1031
. any ( |counter| same_var ( cx, place, counter. id ) )
1027
1032
} else {
@@ -1191,11 +1196,11 @@ fn detect_manual_memcpy<'tcx>(
1191
1196
iter_b = Some ( get_assignment ( body) ) ;
1192
1197
}
1193
1198
1194
- // The only statements in the for loops can be indexed assignments from
1195
- // indexed retrievals.
1196
1199
let assignments = iter_a. into_iter ( ) . flatten ( ) . chain ( iter_b. into_iter ( ) ) ;
1197
1200
1198
1201
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).
1199
1204
. map ( |o| {
1200
1205
o. and_then ( |( lhs, rhs) | {
1201
1206
let rhs = fetch_cloned_expr ( rhs) ;
0 commit comments