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

Better document the implementors of Clone and Copy #48171

Merged
merged 5 commits into from
Apr 4, 2018

Commits on Mar 27, 2018

  1. Move some implementations of Clone and Copy to libcore

    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
    FraGag committed Mar 27, 2018
    Configuration menu
    Copy the full SHA
    27164fa View commit details
    Browse the repository at this point in the history
  2. Document builtin implementations of Clone and Copy

    There are types that implement `Clone` and `Copy` but are not mentioned
    in the documentation, because the implementations are provided by the
    compiler. They are types of variants that cannot be fully covered by
    trait implementations in Rust code, because the language is not
    expressive enough.
    FraGag committed Mar 27, 2018
    Configuration menu
    Copy the full SHA
    f48c043 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    afa7f5b View commit details
    Browse the repository at this point in the history
  4. Strengthen the repeat-trusted-len test

    Simply checking for the presence of `llvm.memset` is too brittle because
    this instrinsic can be used for seemingly trivial operations, such as
    zero-initializing a `RawVec`.
    FraGag committed Mar 27, 2018
    Configuration menu
    Copy the full SHA
    d032a4b View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    87c08f9 View commit details
    Browse the repository at this point in the history