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:
@@ -231,6 +231,7 @@ use error::{FromError, Error};
|
||||
use fmt;
|
||||
use int;
|
||||
use iter::{Iterator, IteratorExt};
|
||||
use kinds::Copy;
|
||||
use mem::transmute;
|
||||
use ops::{BitOr, BitXor, BitAnd, Sub, Not};
|
||||
use option::Option;
|
||||
@@ -420,6 +421,8 @@ pub enum IoErrorKind {
|
||||
NoProgress,
|
||||
}
|
||||
|
||||
impl Copy for IoErrorKind {}
|
||||
|
||||
/// A trait that lets you add a `detail` to an IoError easily
|
||||
trait UpdateIoError<T> {
|
||||
/// Returns an IoError with updated description and detail
|
||||
@@ -1560,6 +1563,8 @@ pub enum SeekStyle {
|
||||
SeekCur,
|
||||
}
|
||||
|
||||
impl Copy for SeekStyle {}
|
||||
|
||||
/// An object implementing `Seek` internally has some form of cursor which can
|
||||
/// be moved within a stream of bytes. The stream typically has a fixed size,
|
||||
/// allowing seeking relative to either end.
|
||||
@@ -1682,6 +1687,8 @@ pub enum FileMode {
|
||||
Truncate,
|
||||
}
|
||||
|
||||
impl Copy for FileMode {}
|
||||
|
||||
/// Access permissions with which the file should be opened. `File`s
|
||||
/// opened with `Read` will return an error if written to.
|
||||
pub enum FileAccess {
|
||||
@@ -1693,6 +1700,8 @@ pub enum FileAccess {
|
||||
ReadWrite,
|
||||
}
|
||||
|
||||
impl Copy for FileAccess {}
|
||||
|
||||
/// Different kinds of files which can be identified by a call to stat
|
||||
#[deriving(PartialEq, Show, Hash, Clone)]
|
||||
pub enum FileType {
|
||||
@@ -1715,6 +1724,8 @@ pub enum FileType {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Copy for FileType {}
|
||||
|
||||
/// A structure used to describe metadata information about a file. This
|
||||
/// structure is created through the `stat` method on a `Path`.
|
||||
///
|
||||
@@ -1766,6 +1777,8 @@ pub struct FileStat {
|
||||
pub unstable: UnstableFileStat,
|
||||
}
|
||||
|
||||
impl Copy for FileStat {}
|
||||
|
||||
/// This structure represents all of the possible information which can be
|
||||
/// returned from a `stat` syscall which is not contained in the `FileStat`
|
||||
/// structure. This information is not necessarily platform independent, and may
|
||||
@@ -1795,6 +1808,8 @@ pub struct UnstableFileStat {
|
||||
pub gen: u64,
|
||||
}
|
||||
|
||||
impl Copy for UnstableFileStat {}
|
||||
|
||||
bitflags! {
|
||||
#[doc = "A set of permissions for a file or directory is represented"]
|
||||
#[doc = "by a set of flags which are or'd together."]
|
||||
@@ -1889,6 +1904,8 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
impl Copy for FilePermission {}
|
||||
|
||||
impl Default for FilePermission {
|
||||
#[inline]
|
||||
fn default() -> FilePermission { FilePermission::empty() }
|
||||
|
||||
Reference in New Issue
Block a user