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:
parent
c7a9b49d1b
commit
096a28607f
277 changed files with 2182 additions and 513 deletions
|
|
@ -55,6 +55,8 @@ pub enum OptLevel {
|
|||
Aggressive // -O3
|
||||
}
|
||||
|
||||
impl Copy for OptLevel {}
|
||||
|
||||
#[deriving(Clone, PartialEq)]
|
||||
pub enum DebugInfoLevel {
|
||||
NoDebugInfo,
|
||||
|
|
@ -62,6 +64,8 @@ pub enum DebugInfoLevel {
|
|||
FullDebugInfo,
|
||||
}
|
||||
|
||||
impl Copy for DebugInfoLevel {}
|
||||
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)]
|
||||
pub enum OutputType {
|
||||
OutputTypeBitcode,
|
||||
|
|
@ -71,6 +75,8 @@ pub enum OutputType {
|
|||
OutputTypeExe,
|
||||
}
|
||||
|
||||
impl Copy for OutputType {}
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub struct Options {
|
||||
// The crate config requested for the session, which may be combined
|
||||
|
|
@ -87,7 +93,7 @@ pub struct Options {
|
|||
// parsed code. It remains mutable in case its replacements wants to use
|
||||
// this.
|
||||
pub addl_lib_search_paths: RefCell<Vec<Path>>,
|
||||
pub libs: Vec<(String, cstore::NativeLibaryKind)>,
|
||||
pub libs: Vec<(String, cstore::NativeLibraryKind)>,
|
||||
pub maybe_sysroot: Option<Path>,
|
||||
pub target_triple: String,
|
||||
// User-specified cfg meta items. The compiler itself will add additional
|
||||
|
|
@ -221,6 +227,8 @@ pub enum EntryFnType {
|
|||
EntryNone,
|
||||
}
|
||||
|
||||
impl Copy for EntryFnType {}
|
||||
|
||||
#[deriving(PartialEq, PartialOrd, Clone, Ord, Eq, Hash)]
|
||||
pub enum CrateType {
|
||||
CrateTypeExecutable,
|
||||
|
|
@ -229,6 +237,8 @@ pub enum CrateType {
|
|||
CrateTypeStaticlib,
|
||||
}
|
||||
|
||||
impl Copy for CrateType {}
|
||||
|
||||
macro_rules! debugging_opts(
|
||||
([ $opt:ident ] $cnt:expr ) => (
|
||||
pub const $opt: u64 = 1 << $cnt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue