fix a FN where incr exprs with no semicolon at ends

This commit is contained in:
rail 2020-10-02 14:18:37 +13:00
parent 94d7b82340
commit 1402d8ae4f
3 changed files with 29 additions and 7 deletions

View File

@ -1014,14 +1014,20 @@ fn get_assignments<'a: 'c, 'tcx: 'c, 'c>(
.iter()
.filter_map(move |stmt| match stmt.kind {
StmtKind::Local(..) | StmtKind::Item(..) => None,
StmtKind::Expr(e) | StmtKind::Semi(e) => if_chain! {
if let ExprKind::AssignOp(_, var, _) = e.kind;
// skip StartKind::Range
if loop_counters.iter().skip(1).any(|counter| Some(counter.id) == var_def_id(cx, var));
then { None } else { Some(e) }
},
StmtKind::Expr(e) | StmtKind::Semi(e) => Some(e),
})
.chain((*expr).into_iter())
.filter(move |e| {
if let ExprKind::AssignOp(_, place, _) = e.kind {
!loop_counters
.iter()
// skip StartKind::Range
.skip(1)
.any(|counter| same_var(cx, place, counter.id))
} else {
true
}
})
.map(get_assignment)
}

View File

@ -59,6 +59,13 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32])
dst[count] = src[i + 2];
count += 1;
}
// make sure incrementing expressions without semicolons at the end of loops are handled correctly.
let mut count = 0;
for i in 3..src.len() {
dst[i] = src[count];
count += 1
}
}
fn main() {}

View File

@ -89,5 +89,14 @@ LL | | count += 1;
LL | | }
| |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)]);`
error: aborting due to 9 previous errors
error: it looks like you're manually copying between slices
--> $DIR/with_loop_counters.rs:65:5
|
LL | / for i in 3..src.len() {
LL | | dst[i] = src[count];
LL | | count += 1
LL | | }
| |_____^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)]);`
error: aborting due to 10 previous errors