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:
Niko Matsakis
2014-12-05 17:01:33 -08:00
parent c7a9b49d1b
commit 096a28607f
277 changed files with 2182 additions and 513 deletions

View File

@@ -44,6 +44,8 @@ pub enum Piece<'a> {
NextArgument(Argument<'a>),
}
impl<'a> Copy for Piece<'a> {}
/// Representation of an argument specification.
#[deriving(PartialEq)]
pub struct Argument<'a> {
@@ -53,6 +55,8 @@ pub struct Argument<'a> {
pub format: FormatSpec<'a>,
}
impl<'a> Copy for Argument<'a> {}
/// Specification for the formatting of an argument in the format string.
#[deriving(PartialEq)]
pub struct FormatSpec<'a> {
@@ -72,6 +76,8 @@ pub struct FormatSpec<'a> {
pub ty: &'a str
}
impl<'a> Copy for FormatSpec<'a> {}
/// Enum describing where an argument for a format can be located.
#[deriving(PartialEq)]
pub enum Position<'a> {
@@ -83,6 +89,8 @@ pub enum Position<'a> {
ArgumentNamed(&'a str),
}
impl<'a> Copy for Position<'a> {}
/// Enum of alignments which are supported.
#[deriving(PartialEq)]
pub enum Alignment {
@@ -96,6 +104,8 @@ pub enum Alignment {
AlignUnknown,
}
impl Copy for Alignment {}
/// Various flags which can be applied to format strings. The meaning of these
/// flags is defined by the formatters themselves.
#[deriving(PartialEq)]
@@ -112,6 +122,8 @@ pub enum Flag {
FlagSignAwareZeroPad,
}
impl Copy for Flag {}
/// A count is used for the precision and width parameters of an integer, and
/// can reference either an argument or a literal integer.
#[deriving(PartialEq)]
@@ -128,6 +140,8 @@ pub enum Count<'a> {
CountImplied,
}
impl<'a> Copy for Count<'a> {}
/// The parser structure for interpreting the input format string. This is
/// modelled as an iterator over `Piece` structures to form a stream of tokens
/// being output.