Skip to content

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

Closed
@thomcc

Description

@thomcc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: 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.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions