-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rustdoc: No mention of copy trait for primitive types #25893
Comments
As mentioned in rust-lang#25893 the copy trait is not very well explained for beginners. There is no clear mention that all primitive types implement the copy trait and there are not a lot of examples. With this change I try to make it more visible and understandable for new users. I myself have struggled with this, see [my question on stackoverflow](http://stackoverflow.com/questions/30540419/why-are-booleans-copyable-even-though-the-documentation-doesnt-indicate-that). And I want to make it more transparent for others. I filed issue rust-lang#25893 but I thought that I could give it a shot myself to relieve some of the work from the devs :) If it is not well written or there are some changes to be made before it can be merged, let me know. Cheers, Mathieu
Triage: no real change. |
@mbrubeck points out that |
This just confused me for the stable-soon never type, where I think it's likely that even experienced rustaceans would be wondering about implemented traits. |
PR #48171 is working on it 😉 |
Add implementations of `Clone` and `Copy` for some primitive types to libcore so that they show up in the documentation. The concerned types are the following: * All primitive signed and unsigned integer types (`usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`); * All primitive floating point types (`f32`, `f64`) * `bool` * `char` * `!` * Raw pointers (`*const T` and `*mut T`) * Shared references (`&'a T`) These types already implemented `Clone` and `Copy`, but the implementation was provided by the compiler. The compiler no longer provides these implementations and instead tries to look them up as normal trait implementations. The goal of this change is to make the implementations appear in the generated documentation. For `Copy` specifically, the compiler would reject an attempt to write an `impl` for the primitive types listed above with error `E0206`; this error no longer occurs for these types, but it will still occur for the other types that used to raise that error. The trait implementations are guarded with `#[cfg(not(stage0))]` because they are invalid according to the stage0 compiler. When the stage0 compiler is updated to a revision that includes this change, the attribute will have to be removed, otherwise the stage0 build will fail because the types mentioned above no longer implement `Clone` or `Copy`. For type variants that are variadic, such as tuples and function pointers, and for array types, the `Clone` and `Copy` implementations are still provided by the compiler, because the language is not expressive enough yet to be able to write the appropriate implementations in Rust. The initial plan was to add `impl` blocks guarded by `#[cfg(dox)]` to make them apply only when generating documentation, without having to touch the compiler. However, rustdoc's usage of the compiler still rejected those `impl` blocks. This is a [breaking-change] for users of `#![no_core]`, because they will now have to supply their own implementations of `Clone` and `Copy` for the primitive types listed above. The easiest way to do that is to simply copy the implementations from `src/libcore/clone.rs` and `src/libcore/marker.rs`. Fixes rust-lang#25893
Better document the implementors of Clone and Copy There are two parts to this change. The first part is a change to the compiler and to the standard library (specifically, libcore) to allow implementations of `Clone` and `Copy` to be written for a subset of builtin types. By adding these implementations to libcore, they now show up in the documentation. This is a [breaking-change] for users of `#![no_core]`, because they will now have to supply their own copy of the implementations of `Clone` and `Copy` that were added in libcore. The second part is purely a documentation change to document the other implementors of `Clone` and `Copy` that cannot be described in Rust code (yet) and are thus provided by the compiler. Fixes #25893
Is it me, or do the docs still not mention the |
Rust has a release cadence of 6 weeks. That commit was merged on Apr 4, starting on the nightly release. Rust 1.26 stable was released on Thu May 10 2018 and this was promoted to beta. You can see Rust 1.27 stable will be released on Thu Jun 21 2018, at which time this will show up in those docs. |
As a new rust user I have struggled with a little problem: http://stackoverflow.com/questions/30540419/rust-ownership-copy-clone-trait
The ownership and borrowing rules are well explained in the docs but the copy trait and the types that implement them are not!
In the doc http://doc.rust-lang.org/std/marker/trait.Copy.html primitive types are not listed as copy trait implementors. They should at least be mentioned there.
It would be good to also add a little more info here: http://doc.rust-lang.org/book/ownership.html#copy-types Maybe give some examples like in my question on stackoverflow:
This is very important since it is an exception to the most important rule of the language
Let me know if I have to make a pull request with a "change proposal" :)
The text was updated successfully, but these errors were encountered: