librustc: Make Copy opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
This commit is contained in:
@@ -90,6 +90,8 @@ pub trait Drop {
|
||||
/// ```rust
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Add<Foo, Foo> for Foo {
|
||||
/// fn add(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Adding!");
|
||||
@@ -128,6 +130,8 @@ add_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
|
||||
/// ```rust
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Sub<Foo, Foo> for Foo {
|
||||
/// fn sub(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Subtracting!");
|
||||
@@ -166,6 +170,8 @@ sub_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
|
||||
/// ```rust
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Mul<Foo, Foo> for Foo {
|
||||
/// fn mul(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Multiplying!");
|
||||
@@ -204,6 +210,8 @@ mul_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Div<Foo, Foo> for Foo {
|
||||
/// fn div(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Dividing!");
|
||||
@@ -242,6 +250,8 @@ div_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Rem<Foo, Foo> for Foo {
|
||||
/// fn rem(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Remainder-ing!");
|
||||
@@ -294,6 +304,8 @@ rem_float_impl!(f64, fmod)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Neg<Foo> for Foo {
|
||||
/// fn neg(&self) -> Foo {
|
||||
/// println!("Negating!");
|
||||
@@ -348,6 +360,8 @@ neg_uint_impl!(u64, i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Not<Foo> for Foo {
|
||||
/// fn not(&self) -> Foo {
|
||||
/// println!("Not-ing!");
|
||||
@@ -387,6 +401,8 @@ not_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl BitAnd<Foo, Foo> for Foo {
|
||||
/// fn bitand(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Bitwise And-ing!");
|
||||
@@ -425,6 +441,8 @@ bitand_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl BitOr<Foo, Foo> for Foo {
|
||||
/// fn bitor(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Bitwise Or-ing!");
|
||||
@@ -463,6 +481,8 @@ bitor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl BitXor<Foo, Foo> for Foo {
|
||||
/// fn bitxor(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Bitwise Xor-ing!");
|
||||
@@ -501,6 +521,8 @@ bitxor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Shl<Foo, Foo> for Foo {
|
||||
/// fn shl(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Shifting left!");
|
||||
@@ -541,6 +563,8 @@ shl_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Shr<Foo, Foo> for Foo {
|
||||
/// fn shr(&self, _rhs: &Foo) -> Foo {
|
||||
/// println!("Shifting right!");
|
||||
@@ -580,6 +604,8 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Index<Foo, Foo> for Foo {
|
||||
/// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo {
|
||||
/// println!("Indexing!");
|
||||
@@ -608,6 +634,8 @@ pub trait Index<Sized? Index, Sized? Result> for Sized? {
|
||||
/// ```
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl IndexMut<Foo, Foo> for Foo {
|
||||
/// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo {
|
||||
/// println!("Indexing!");
|
||||
@@ -636,6 +664,8 @@ pub trait IndexMut<Sized? Index, Sized? Result> for Sized? {
|
||||
/// ```ignore
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl Slice<Foo, Foo> for Foo {
|
||||
/// fn as_slice_<'a>(&'a self) -> &'a Foo {
|
||||
/// println!("Slicing!");
|
||||
@@ -682,6 +712,8 @@ pub trait Slice<Sized? Idx, Sized? Result> for Sized? {
|
||||
/// ```ignore
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Copy for Foo {}
|
||||
///
|
||||
/// impl SliceMut<Foo, Foo> for Foo {
|
||||
/// fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
|
||||
/// println!("Slicing!");
|
||||
|
||||
Reference in New Issue
Block a user