27164faaef
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 #25893
54 lines
1.8 KiB
Rust
54 lines
1.8 KiB
Rust
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
#![feature(optin_builtin_traits)]
|
|
|
|
use std::marker::Copy;
|
|
|
|
impl Copy for i32 {}
|
|
//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `i32`:
|
|
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
|
|
|
|
enum TestE {
|
|
A
|
|
}
|
|
|
|
struct MyType;
|
|
|
|
struct NotSync;
|
|
impl !Sync for NotSync {}
|
|
|
|
impl Copy for TestE {}
|
|
impl Clone for TestE { fn clone(&self) -> Self { *self } }
|
|
|
|
impl Copy for MyType {}
|
|
|
|
impl Copy for &'static mut MyType {}
|
|
//~^ ERROR the trait `Copy` may not be implemented for this type
|
|
impl Clone for MyType { fn clone(&self) -> Self { *self } }
|
|
|
|
impl Copy for (MyType, MyType) {}
|
|
//~^ ERROR the trait `Copy` may not be implemented for this type
|
|
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
|
|
|
|
impl Copy for &'static NotSync {}
|
|
//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `&NotSync`:
|
|
|
|
impl Copy for [MyType] {}
|
|
//~^ ERROR the trait `Copy` may not be implemented for this type
|
|
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
|
|
|
|
impl Copy for &'static [NotSync] {}
|
|
//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `&[NotSync]`:
|
|
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
|
|
|
|
fn main() {
|
|
}
|