From 096a28607fb80c91e6e2ca64d9ef44c4e550e96c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 5 Dec 2014 17:01:33 -0800 Subject: 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] --- src/libsyntax/codemap.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libsyntax/codemap.rs') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 6bcf562204b..50b4f342368 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -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 { pub span: Span, } +impl Copy for Spanned {} + 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 -- cgit 1.4.1-3-g733a5