Closed
Description
The docs for ptr::copy_nonoverlapping
and ptr::copy
say things like:
copy is semantically equivalent to C's memmove, but with the argument order swapped
and
copy_nonoverlapping is semantically equivalent to C's memcpy, but with the argument order swapped.
This is true, but I just encountered code where these were more-or-less used as:
ptr::copy_nonoverlapping(a, b, size_of::<T>() * n);
and the author (and myself) were confused about the issue here due to this basically looking right. The problem here is that unlike memcpy
/memmove
the size_of::<T>() * n
should just be n
, since it's the number of T
s to copy.
I've filed a clippy lint for this: rust-lang/rust-clippy#6381, but the docs should be updated to clarify this difference.