Skip to content

Commit

Permalink
Don't reborrow self when computing the dest pointer in <[T]>::copy_wi…
Browse files Browse the repository at this point in the history
…thin
  • Loading branch information
SkiFire13 committed May 23, 2021
1 parent 13bf0b2 commit d7341f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,11 @@ impl<T> [T] {
// SAFETY: the conditions for `ptr::copy` have all been checked above,
// as have those for `ptr::add`.
unsafe {
ptr::copy(self.as_ptr().add(src_start), self.as_mut_ptr().add(dest), count);
// Derive both `src_ptr` and `dest_ptr` from the same loan
let ptr = self.as_mut_ptr();
let src_ptr = ptr.add(src_start);
let dest_ptr = ptr.add(dest);
ptr::copy(src_ptr, dest_ptr, count);
}
}

Expand Down

0 comments on commit d7341f3

Please sign in to comment.