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

@@ -34,12 +34,16 @@ pub trait Pos {
#[deriving(Clone, PartialEq, Eq, Hash, PartialOrd, Show)]
pub struct BytePos(pub u32);
impl Copy for BytePos {}
/// A character offset. Because of multibyte utf8 characters, a byte offset
/// is not equivalent to a character offset. The CodeMap will convert BytePos
/// values to CharPos values as necessary.
#[deriving(PartialEq, Hash, PartialOrd, Show)]
pub struct CharPos(pub uint);
impl Copy for CharPos {}
// FIXME: Lots of boilerplate in these impls, but so far my attempts to fix
// have been unsuccessful
@@ -90,6 +94,8 @@ pub struct Span {
pub expn_id: ExpnId
}
impl Copy for Span {}
pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION };
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
@@ -98,6 +104,8 @@ pub struct Spanned<T> {
pub span: Span,
}
impl<T:Copy> Copy for Spanned<T> {}
impl PartialEq for Span {
fn eq(&self, other: &Span) -> bool {
return (*self).lo == (*other).lo && (*self).hi == (*other).hi;
@@ -183,6 +191,8 @@ pub enum MacroFormat {
MacroBang
}
impl Copy for MacroFormat {}
#[deriving(Clone, Hash, Show)]
pub struct NameAndSpan {
/// The name of the macro that was invoked to create the thing
@@ -221,6 +231,8 @@ pub struct ExpnInfo {
#[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)]
pub struct ExpnId(u32);
impl Copy for ExpnId {}
pub const NO_EXPANSION: ExpnId = ExpnId(-1);
impl ExpnId {
@@ -249,6 +261,8 @@ pub struct MultiByteChar {
pub bytes: uint,
}
impl Copy for MultiByteChar {}
/// A single source in the CodeMap
pub struct FileMap {
/// The name of the file that the source came from, source that doesn't