-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.