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

@ -24,6 +24,8 @@ pub enum OptimizationDiagnosticKind {
OptimizationFailure,
}
impl Copy for OptimizationDiagnosticKind {}
impl OptimizationDiagnosticKind {
pub fn describe(self) -> &'static str {
match self {
@ -43,6 +45,8 @@ pub struct OptimizationDiagnostic {
pub message: TwineRef,
}
impl Copy for OptimizationDiagnostic {}
impl OptimizationDiagnostic {
unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef)
-> OptimizationDiagnostic {
@ -72,6 +76,8 @@ pub enum Diagnostic {
UnknownDiagnostic(DiagnosticInfoRef),
}
impl Copy for Diagnostic {}
impl Diagnostic {
pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic {
let kind = super::LLVMGetDiagInfoKind(di);

View file

@ -77,12 +77,16 @@ pub enum CallConv {
X86_64_Win64 = 79,
}
impl Copy for CallConv {}
pub enum Visibility {
LLVMDefaultVisibility = 0,
HiddenVisibility = 1,
ProtectedVisibility = 2,
}
impl Copy for Visibility {}
// This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
// DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
// LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
@ -101,6 +105,8 @@ pub enum Linkage {
CommonLinkage = 14,
}
impl Copy for Linkage {}
#[repr(C)]
#[deriving(Show)]
pub enum DiagnosticSeverity {
@ -110,6 +116,8 @@ pub enum DiagnosticSeverity {
Note,
}
impl Copy for DiagnosticSeverity {}
bitflags! {
flags Attribute : u32 {
const ZExtAttribute = 1 << 0,
@ -141,6 +149,8 @@ bitflags! {
}
}
impl Copy for Attribute {}
#[repr(u64)]
pub enum OtherAttribute {
// The following are not really exposed in
@ -162,16 +172,22 @@ pub enum OtherAttribute {
NonNullAttribute = 1 << 44,
}
impl Copy for OtherAttribute {}
pub enum SpecialAttribute {
DereferenceableAttribute(u64)
}
impl Copy for SpecialAttribute {}
#[repr(C)]
pub enum AttributeSet {
ReturnIndex = 0,
FunctionIndex = !0
}
impl Copy for AttributeSet {}
pub trait AttrHelper {
fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
@ -271,6 +287,8 @@ pub enum IntPredicate {
IntSLE = 41,
}
impl Copy for IntPredicate {}
// enum for the LLVM RealPredicate type
pub enum RealPredicate {
RealPredicateFalse = 0,
@ -291,6 +309,8 @@ pub enum RealPredicate {
RealPredicateTrue = 15,
}
impl Copy for RealPredicate {}
// The LLVM TypeKind type - must stay in sync with the def of
// LLVMTypeKind in llvm/include/llvm-c/Core.h
#[deriving(PartialEq)]
@ -314,6 +334,8 @@ pub enum TypeKind {
X86_MMX = 15,
}
impl Copy for TypeKind {}
#[repr(C)]
pub enum AtomicBinOp {
AtomicXchg = 0,
@ -329,6 +351,8 @@ pub enum AtomicBinOp {
AtomicUMin = 10,
}
impl Copy for AtomicBinOp {}
#[repr(C)]
pub enum AtomicOrdering {
NotAtomic = 0,
@ -341,6 +365,8 @@ pub enum AtomicOrdering {
SequentiallyConsistent = 7
}
impl Copy for AtomicOrdering {}
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
#[repr(C)]
pub enum FileType {
@ -348,6 +374,8 @@ pub enum FileType {
ObjectFileType = 1
}
impl Copy for FileType {}
pub enum MetadataType {
MD_dbg = 0,
MD_tbaa = 1,
@ -357,12 +385,16 @@ pub enum MetadataType {
MD_tbaa_struct = 5
}
impl Copy for MetadataType {}
// Inline Asm Dialect
pub enum AsmDialect {
AD_ATT = 0,
AD_Intel = 1
}
impl Copy for AsmDialect {}
#[deriving(PartialEq, Clone)]
#[repr(C)]
pub enum CodeGenOptLevel {
@ -372,6 +404,8 @@ pub enum CodeGenOptLevel {
CodeGenLevelAggressive = 3,
}
impl Copy for CodeGenOptLevel {}
#[deriving(PartialEq)]
#[repr(C)]
pub enum RelocMode {
@ -381,6 +415,8 @@ pub enum RelocMode {
RelocDynamicNoPic = 3,
}
impl Copy for RelocMode {}
#[repr(C)]
pub enum CodeGenModel {
CodeModelDefault = 0,
@ -391,6 +427,8 @@ pub enum CodeGenModel {
CodeModelLarge = 5,
}
impl Copy for CodeGenModel {}
#[repr(C)]
pub enum DiagnosticKind {
DK_InlineAsm = 0,
@ -403,47 +441,70 @@ pub enum DiagnosticKind {
DK_OptimizationFailure,
}
impl Copy for DiagnosticKind {}
// Opaque pointer types
#[allow(missing_copy_implementations)]
pub enum Module_opaque {}
pub type ModuleRef = *mut Module_opaque;
#[allow(missing_copy_implementations)]
pub enum Context_opaque {}
pub type ContextRef = *mut Context_opaque;
#[allow(missing_copy_implementations)]
pub enum Type_opaque {}
pub type TypeRef = *mut Type_opaque;
#[allow(missing_copy_implementations)]
pub enum Value_opaque {}
pub type ValueRef = *mut Value_opaque;
#[allow(missing_copy_implementations)]
pub enum BasicBlock_opaque {}
pub type BasicBlockRef = *mut BasicBlock_opaque;
#[allow(missing_copy_implementations)]
pub enum Builder_opaque {}
pub type BuilderRef = *mut Builder_opaque;
#[allow(missing_copy_implementations)]
pub enum ExecutionEngine_opaque {}
pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
#[allow(missing_copy_implementations)]
pub enum MemoryBuffer_opaque {}
pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
#[allow(missing_copy_implementations)]
pub enum PassManager_opaque {}
pub type PassManagerRef = *mut PassManager_opaque;
#[allow(missing_copy_implementations)]
pub enum PassManagerBuilder_opaque {}
pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
#[allow(missing_copy_implementations)]
pub enum Use_opaque {}
pub type UseRef = *mut Use_opaque;
#[allow(missing_copy_implementations)]
pub enum TargetData_opaque {}
pub type TargetDataRef = *mut TargetData_opaque;
#[allow(missing_copy_implementations)]
pub enum ObjectFile_opaque {}
pub type ObjectFileRef = *mut ObjectFile_opaque;
#[allow(missing_copy_implementations)]
pub enum SectionIterator_opaque {}
pub type SectionIteratorRef = *mut SectionIterator_opaque;
#[allow(missing_copy_implementations)]
pub enum Pass_opaque {}
pub type PassRef = *mut Pass_opaque;
#[allow(missing_copy_implementations)]
pub enum TargetMachine_opaque {}
pub type TargetMachineRef = *mut TargetMachine_opaque;
#[allow(missing_copy_implementations)]
pub enum Archive_opaque {}
pub type ArchiveRef = *mut Archive_opaque;
#[allow(missing_copy_implementations)]
pub enum Twine_opaque {}
pub type TwineRef = *mut Twine_opaque;
#[allow(missing_copy_implementations)]
pub enum DiagnosticInfo_opaque {}
pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
#[allow(missing_copy_implementations)]
pub enum DebugLoc_opaque {}
pub type DebugLocRef = *mut DebugLoc_opaque;
#[allow(missing_copy_implementations)]
pub enum SMDiagnostic_opaque {}
pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
@ -454,6 +515,7 @@ pub mod debuginfo {
pub use self::DIDescriptorFlags::*;
use super::{ValueRef};
#[allow(missing_copy_implementations)]
pub enum DIBuilder_opaque {}
pub type DIBuilderRef = *mut DIBuilder_opaque;
@ -490,6 +552,8 @@ pub mod debuginfo {
FlagLValueReference = 1 << 14,
FlagRValueReference = 1 << 15
}
impl Copy for DIDescriptorFlags {}
}
@ -2123,6 +2187,7 @@ pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
}
}
#[allow(missing_copy_implementations)]
pub enum RustString_opaque {}
pub type RustStringRef = *mut RustString_opaque;
type RustStringRepr = *mut RefCell<Vec<u8>>;