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

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

Closed
chordowl opened this issue Mar 1, 2018 · 3 comments
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. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@chordowl
Copy link
Contributor

chordowl commented Mar 1, 2018

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.

@steveklabnik
Copy link
Member

Yes, this was changed at some point...

@pietroalbini pietroalbini 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 labels Mar 2, 2018
@steveklabnik steveklabnik added the E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. label May 28, 2018
@steveklabnik
Copy link
Member

Tagging as E-hard simply because we need to track down what the answer is; once that's done it will be E-easy.

@steveklabnik steveklabnik added the P-medium Medium priority label Dec 27, 2018
@jonas-schievink jonas-schievink added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 6, 2020
@jonas-schievink
Copy link
Contributor

Triage:

The Clone docs say:

In addition to the implementors listed below, the following types also implement Clone:
...

  • Array types, for all sizes, if the item type also implements Clone (e.g., [i32; 123456])

The array primitive docs say:

Arrays of any size are Copy if the element type is Copy and Clone if the element type is Clone. This works because Copy and Clone traits are specially known to the compiler.

Closing as fixed.

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. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants