Merge pull request #2147 from clippered/fix-manual-memcpy-on-overlapping-slices

Fix #2123 : check that the source and destination are different for m…
This commit is contained in:
Oliver Schneider 2017-10-20 09:27:15 +02:00 committed by GitHub
commit 327d995bb6
2 changed files with 16 additions and 1 deletions

View file

@ -749,7 +749,14 @@ fn get_indexed_assignments<'a, 'tcx>(
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
if let Expr_::ExprAssign(ref lhs, ref rhs) = e.node {
match (get_fixed_offset_var(cx, lhs, var), fetch_cloned_fixed_offset_var(cx, rhs, var)) {
(Some(offset_left), Some(offset_right)) => Some((offset_left, offset_right)),
(Some(offset_left), Some(offset_right)) => {
// Source and destination must be different
if offset_left.var_name != offset_right.var_name {
Some((offset_left, offset_right))
} else {
None
}
},
_ => None,
}
} else {

View file

@ -548,3 +548,11 @@ pub fn manual_clone(src: &[String], dst: &mut [String]) {
dst[i] = src[i].clone();
}
}
#[warn(needless_range_loop)]
pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) {
// Same source and destination - don't trigger lint
for i in 0..dst.len() {
dst[d + i] = dst[s + i];
}
}