Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptr::copy_nonoverlapping/ptr::copy docs mention order difference between memcpy/memmove but fail to note count unit difference #79430

Closed
thomcc opened this issue Nov 25, 2020 · 0 comments · Fixed by #136359
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@thomcc
Copy link
Member

thomcc commented Nov 25, 2020

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 Ts 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.

@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 25, 2020
jhpratt added a commit to jhpratt/rust that referenced this issue Mar 16, 2025
doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove

Fixes rust-lang#79430
@bors bors closed this as completed in feb6cb4 Mar 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2025
Rollup merge of rust-lang#136359 - hkBst:ptr_copy_docs, r=Amanieu

doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove

Fixes rust-lang#79430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants