Skip to content

Documentation for Clone is inaccurate w/r/t large arrays (always?) not implementing Clone. #48646

Closed
@chordowl

Description

@chordowl

Currently, the Clone docs state that Clone is not implemented for arrays with more than 32 elements:

/// An example is an array holding more than 32 elements of a type that is `Clone`; the standard
/// library only implements `Clone` up until arrays of size 32. In this case, the implementation of
/// `Clone` cannot be `derive`d, but can be implemented as:
///
/// [`Copy`]: ../../std/marker/trait.Copy.html
/// [`clone`]: trait.Clone.html#tymethod.clone
///
/// ```
/// #[derive(Copy)]
/// struct Stats {
/// frequencies: [i32; 100],
/// }
///
/// impl Clone for Stats {
/// fn clone(&self) -> Stats { *self }
/// }
/// ```

This seems to be untrue, at least for the given example: playground. This must've been the case since at least 1.21.0.

I would fix this myself, but unfortunately, from the PR linked in the changelog, I'm not quite sure in which circumstances Clone is now auto-implemented. I didn't just want to rip out the example without providing a new one that makes more sense for the current situation.

Edit: to prevent this from happening again, it might be nice to have an additional compile_fail-style example in the docs to show what doesn't work, so that doctests can catch it.

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.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.P-mediumMedium priorityT-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