diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-12-05 17:01:33 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-12-08 13:47:44 -0500 |
| commit | 096a28607fb80c91e6e2ca64d9ef44c4e550e96c (patch) | |
| tree | 82c4ee8f20df133305959d507ec76adb4db5e324 /src/test | |
| parent | c7a9b49d1b5d4e520f25355f26a93dfac4ffa146 (diff) | |
| download | rust-096a28607fb80c91e6e2ca64d9ef44c4e550e96c.tar.gz rust-096a28607fb80c91e6e2ca64d9ef44c4e550e96c.zip | |
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]
Diffstat (limited to 'src/test')
103 files changed, 340 insertions, 196 deletions
diff --git a/src/test/auxiliary/issue-14422.rs b/src/test/auxiliary/issue-14422.rs index 04e1d993011..9ecb1195de0 100644 --- a/src/test/auxiliary/issue-14422.rs +++ b/src/test/auxiliary/issue-14422.rs @@ -25,6 +25,8 @@ mod src { pub struct A; + impl Copy for A {} + pub fn make() -> B { A } impl A { diff --git a/src/test/auxiliary/issue13213aux.rs b/src/test/auxiliary/issue13213aux.rs index 5bd52ef5010..cf8d0c167a1 100644 --- a/src/test/auxiliary/issue13213aux.rs +++ b/src/test/auxiliary/issue13213aux.rs @@ -22,6 +22,10 @@ mod private { p: i32, } pub const THREE: P = P { p: 3 }; + impl Copy for P {} } pub static A: S = S { p: private::THREE }; + +impl Copy for S {} + diff --git a/src/test/auxiliary/lang-item-public.rs b/src/test/auxiliary/lang-item-public.rs index ea2461ccfa8..e6bae462887 100644 --- a/src/test/auxiliary/lang-item-public.rs +++ b/src/test/auxiliary/lang-item-public.rs @@ -22,3 +22,8 @@ extern fn stack_exhausted() {} #[lang = "eh_personality"] extern fn eh_personality() {} + +#[lang="copy"] +pub trait Copy {} + + diff --git a/src/test/auxiliary/method_self_arg1.rs b/src/test/auxiliary/method_self_arg1.rs index d02222931e5..37022131c3d 100644 --- a/src/test/auxiliary/method_self_arg1.rs +++ b/src/test/auxiliary/method_self_arg1.rs @@ -16,6 +16,8 @@ pub fn get_count() -> u64 { unsafe { COUNT } } pub struct Foo; +impl Copy for Foo {} + impl Foo { pub fn foo(self, x: &Foo) { unsafe { COUNT *= 2; } diff --git a/src/test/auxiliary/method_self_arg2.rs b/src/test/auxiliary/method_self_arg2.rs index 99eb665388b..e1e79b59e3e 100644 --- a/src/test/auxiliary/method_self_arg2.rs +++ b/src/test/auxiliary/method_self_arg2.rs @@ -16,6 +16,8 @@ pub fn get_count() -> u64 { unsafe { COUNT } } pub struct Foo; +impl Copy for Foo {} + impl Foo { pub fn run_trait(self) { unsafe { COUNT *= 17; } diff --git a/src/test/auxiliary/xcrate_unit_struct.rs b/src/test/auxiliary/xcrate_unit_struct.rs index d56d7a70edf..5a918db1cfa 100644 --- a/src/test/auxiliary/xcrate_unit_struct.rs +++ b/src/test/auxiliary/xcrate_unit_struct.rs @@ -14,20 +14,31 @@ pub struct Struct; +impl Copy for Struct {} + pub enum Unit { UnitVariant, Argument(Struct) } +impl Copy for Unit {} + pub struct TupleStruct(pub uint, pub &'static str); +impl Copy for TupleStruct {} + // used by the cfail test pub struct StructWithFields { foo: int, } +impl Copy for StructWithFields {} + pub enum EnumWithVariants { EnumVariant, EnumVariantArg(int) } + +impl Copy for EnumWithVariants {} + diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 419e39b53cf..025f8467d20 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -21,6 +21,8 @@ struct Vec2 { y: f32, } +impl Copy for Vec2 {} + fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v } fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 3059a014528..e954d0fed5e 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -53,7 +53,14 @@ fn print_complements() { } } -enum Color { Red, Yellow, Blue } +enum Color { + Red, + Yellow, + Blue, +} + +impl Copy for Color {} + impl fmt::Show for Color { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let str = match *self { @@ -70,6 +77,8 @@ struct CreatureInfo { color: Color } +impl Copy for CreatureInfo {} + fn show_color_list(set: Vec<Color>) -> String { let mut out = String::new(); for col in set.iter() { diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index b38b8e66d7d..4b890bbd8d3 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -67,6 +67,8 @@ struct P { p: [i32, .. 16], } +impl Copy for P {} + struct Perm { cnt: [i32, .. 16], fact: [u32, .. 16], @@ -75,6 +77,8 @@ struct Perm { perm: P, } +impl Copy for Perm {} + impl Perm { fn new(n: u32) -> Perm { let mut fact = [1, .. 16]; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 0b4a1d91968..afffbe5bed4 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -109,6 +109,8 @@ struct AminoAcid { p: f32, } +impl Copy for AminoAcid {} + struct RepeatFasta<'a, W:'a> { alu: &'static str, out: &'a mut W diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 8ed041513c4..847ae2c1c88 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -62,6 +62,8 @@ static OCCURRENCES: [&'static str, ..5] = [ #[deriving(PartialEq, PartialOrd, Ord, Eq)] struct Code(u64); +impl Copy for Code {} + impl Code { fn hash(&self) -> u64 { let Code(ret) = *self; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index b62504d7ba8..3f36c16aff6 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -100,6 +100,8 @@ struct Planet { mass: f64, } +impl Copy for Planet {} + fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: int) { for _ in range(0, steps) { let mut b_slice = bodies.as_mut_slice(); diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs index c071691c947..d5998c8ca99 100644 --- a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs +++ b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs @@ -14,11 +14,15 @@ struct Foo { bar2: Bar } +impl Copy for Foo {} + struct Bar { int1: int, int2: int, } +impl Copy for Bar {} + fn make_foo() -> Box<Foo> { panic!() } fn borrow_same_field_twice_mut_mut() { diff --git a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs index 3a85b45ad12..d252d442297 100644 --- a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs +++ b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs @@ -13,11 +13,15 @@ struct Foo { bar2: Bar } +impl Copy for Foo {} + struct Bar { int1: int, int2: int, } +impl Copy for Bar {} + fn make_foo() -> Foo { panic!() } fn borrow_same_field_twice_mut_mut() { diff --git a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs deleted file mode 100644 index 2063d7388a9..00000000000 --- a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -enum Either<T, U> { Left(T), Right(U) } - - fn f(x: &mut Either<int,f64>, y: &Either<int,f64>) -> int { - match *y { - Either::Left(ref z) => { - *x = Either::Right(1.0); - *z - } - _ => panic!() - } - } - - fn g() { - let mut x: Either<int,f64> = Either::Left(3); - println!("{}", f(&mut x, &x)); //~ ERROR cannot borrow - } - - fn h() { - let mut x: Either<int,f64> = Either::Left(3); - let y: &Either<int, f64> = &x; - let z: &mut Either<int, f64> = &mut x; //~ ERROR cannot borrow - *z = *y; - } - - fn main() {} diff --git a/src/test/compile-fail/borrowck-use-mut-borrow.rs b/src/test/compile-fail/borrowck-use-mut-borrow.rs index 7414bb930d4..0d27473cb2d 100644 --- a/src/test/compile-fail/borrowck-use-mut-borrow.rs +++ b/src/test/compile-fail/borrowck-use-mut-borrow.rs @@ -9,6 +9,9 @@ // except according to those terms. struct A { a: int, b: int } + +impl Copy for A {} + struct B { a: int, b: Box<int> } fn var_copy_after_var_borrow() { diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index f6511d68662..af97c864dc8 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -16,6 +16,8 @@ use std::fmt::Show; struct S; +impl Copy for S {} + impl Index<uint, str> for S { fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" @@ -24,6 +26,8 @@ impl Index<uint, str> for S { struct T; +impl Copy for T {} + impl Index<uint, Show + 'static> for T { fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; @@ -33,7 +37,8 @@ impl Index<uint, Show + 'static> for T { fn main() { S[0]; - //~^ ERROR E0161 + //~^ ERROR cannot move out of dereference + //~^^ ERROR E0161 T[0]; //~^ ERROR cannot move out of dereference //~^^ ERROR E0161 diff --git a/src/test/compile-fail/dst-rvalue.rs b/src/test/compile-fail/dst-rvalue.rs index 52b7ea9efa5..4c1dafd8c1a 100644 --- a/src/test/compile-fail/dst-rvalue.rs +++ b/src/test/compile-fail/dst-rvalue.rs @@ -13,8 +13,10 @@ pub fn main() { let _x: Box<str> = box *"hello world"; //~^ ERROR E0161 + //~^^ ERROR cannot move out of dereference let array: &[int] = &[1, 2, 3]; let _x: Box<[int]> = box *array; //~^ ERROR E0161 + //~^^ ERROR cannot move out of dereference } diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs index ef8174a26aa..ab396edddf4 100644 --- a/src/test/compile-fail/issue-17651.rs +++ b/src/test/compile-fail/issue-17651.rs @@ -13,5 +13,6 @@ fn main() { (|| box *[0u].as_slice())(); - //~^ ERROR cannot move a value of type [uint] + //~^ ERROR cannot move out of dereference + //~^^ ERROR cannot move a value of type [uint] } diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index f0c4a4243ac..8868c7f8256 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -14,6 +14,7 @@ use std::rc::Rc; fn assert_copy<T:Copy>() { } + trait Dummy { } struct MyStruct { @@ -21,6 +22,8 @@ struct MyStruct { y: int, } +impl Copy for MyStruct {} + struct MyNoncopyStruct { x: Box<char>, } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 1a4a87e608b..9e5f15c2721 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -12,6 +12,7 @@ #![allow(unused_variables)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] +#![allow(missing_copy_implementations)] #![deny(dead_code)] #![crate_type="lib"] diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index 8d4ecde692d..b73c3fa2610 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -13,6 +13,7 @@ #![feature(globs)] #![deny(missing_docs)] #![allow(dead_code)] +#![allow(missing_copy_implementations)] //! Some garbage docs for the crate here #![doc="More garbage"] diff --git a/src/test/compile-fail/opt-in-copy.rs b/src/test/compile-fail/opt-in-copy.rs new file mode 100644 index 00000000000..56f71c844ac --- /dev/null +++ b/src/test/compile-fail/opt-in-copy.rs @@ -0,0 +1,33 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct CantCopyThis; + +struct IWantToCopyThis { + but_i_cant: CantCopyThis, +} + +impl Copy for IWantToCopyThis {} +//~^ ERROR the trait `Copy` may not be implemented for this type + +enum CantCopyThisEither { + A, + B, +} + +enum IWantToCopyThisToo { + ButICant(CantCopyThisEither), +} + +impl Copy for IWantToCopyThisToo {} +//~^ ERROR the trait `Copy` may not be implemented for this type + +fn main() {} + diff --git a/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs b/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs deleted file mode 100644 index 1d1b244ab5a..00000000000 --- a/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// A zero-dependency test that covers some basic traits, default -// methods, etc. When mucking about with basic type system stuff I -// often encounter problems in the iterator trait, so it's useful to -// have hanging around. -nmatsakis - -// error-pattern: requires `start` lang_item - -#![no_std] -#![feature(lang_items)] - -#[lang = "sized"] -pub trait Sized for Sized? { - // Empty. -} - -pub mod std { - pub mod clone { - pub trait Clone { - fn clone(&self) -> Self; - } - } -} - -pub struct ContravariantLifetime<'a>; - -impl <'a> ::std::clone::Clone for ContravariantLifetime<'a> { - #[inline] - fn clone(&self) -> ContravariantLifetime<'a> { - match *self { ContravariantLifetime => ContravariantLifetime, } - } -} - -fn main() { } diff --git a/src/test/compile-fail/stage0-cmp.rs b/src/test/compile-fail/stage0-cmp.rs deleted file mode 100644 index f68eb6400fa..00000000000 --- a/src/test/compile-fail/stage0-cmp.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// A zero-dependency test that covers some basic traits, default -// methods, etc. When mucking about with basic type system stuff I -// often encounter problems in the iterator trait, so it's useful to -// have hanging around. -nmatsakis - -// error-pattern: requires `start` lang_item - -#![no_std] -#![feature(lang_items)] - -#[lang = "sized"] -pub trait Sized for Sized? { - // Empty. -} - -#[unstable = "Definition may change slightly after trait reform"] -pub trait PartialEq for Sized? { - /// This method tests for `self` and `other` values to be equal, and is used by `==`. - fn eq(&self, other: &Self) -> bool; -} - -#[unstable = "Trait is unstable."] -impl<'a, Sized? T: PartialEq> PartialEq for &'a T { - #[inline] - fn eq(&self, other: & &'a T) -> bool { PartialEq::eq(*self, *other) } -} - -fn main() { } diff --git a/src/test/debuginfo/c-style-enum.rs b/src/test/debuginfo/c-style-enum.rs index fec1d1b2789..b0a0142f6dd 100644 --- a/src/test/debuginfo/c-style-enum.rs +++ b/src/test/debuginfo/c-style-enum.rs @@ -104,18 +104,21 @@ use self::AutoDiscriminant::{One, Two, Three}; use self::ManualDiscriminant::{OneHundred, OneThousand, OneMillion}; use self::SingleVariant::TheOnlyVariant; +#[deriving(Copy)] enum AutoDiscriminant { One, Two, Three } +#[deriving(Copy)] enum ManualDiscriminant { OneHundred = 100, OneThousand = 1000, OneMillion = 1000000 } +#[deriving(Copy)] enum SingleVariant { TheOnlyVariant } diff --git a/src/test/debuginfo/generic-method-on-generic-struct.rs b/src/test/debuginfo/generic-method-on-generic-struct.rs index 7ceac0e7cea..4c0c82efea3 100644 --- a/src/test/debuginfo/generic-method-on-generic-struct.rs +++ b/src/test/debuginfo/generic-method-on-generic-struct.rs @@ -147,3 +147,6 @@ fn main() { } fn zzz() {()} + +impl<T:Copy> Copy for Struct<T> {} + diff --git a/src/test/debuginfo/method-on-enum.rs b/src/test/debuginfo/method-on-enum.rs index d86aa54f451..8cb8fae75cf 100644 --- a/src/test/debuginfo/method-on-enum.rs +++ b/src/test/debuginfo/method-on-enum.rs @@ -148,3 +148,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Enum {} + diff --git a/src/test/debuginfo/method-on-generic-struct.rs b/src/test/debuginfo/method-on-generic-struct.rs index 2455c7aa519..d4244ee27d4 100644 --- a/src/test/debuginfo/method-on-generic-struct.rs +++ b/src/test/debuginfo/method-on-generic-struct.rs @@ -147,3 +147,6 @@ fn main() { } fn zzz() {()} + +impl<T:Copy> Copy for Struct<T> {} + diff --git a/src/test/debuginfo/method-on-struct.rs b/src/test/debuginfo/method-on-struct.rs index 5e47d32e376..ca00587ba44 100644 --- a/src/test/debuginfo/method-on-struct.rs +++ b/src/test/debuginfo/method-on-struct.rs @@ -146,3 +146,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-trait.rs b/src/test/debuginfo/method-on-trait.rs index 4d5f53fc120..e70f86a5367 100644 --- a/src/test/debuginfo/method-on-trait.rs +++ b/src/test/debuginfo/method-on-trait.rs @@ -152,3 +152,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-tuple-struct.rs b/src/test/debuginfo/method-on-tuple-struct.rs index fb3bede37fd..31bdd20e409 100644 --- a/src/test/debuginfo/method-on-tuple-struct.rs +++ b/src/test/debuginfo/method-on-tuple-struct.rs @@ -144,3 +144,6 @@ fn main() { } fn zzz() {()} + +impl Copy for TupleStruct {} + diff --git a/src/test/debuginfo/self-in-default-method.rs b/src/test/debuginfo/self-in-default-method.rs index 287813a959f..87fdb2c42c8 100644 --- a/src/test/debuginfo/self-in-default-method.rs +++ b/src/test/debuginfo/self-in-default-method.rs @@ -148,3 +148,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/self-in-generic-default-method.rs b/src/test/debuginfo/self-in-generic-default-method.rs index bfb8abc9f66..6f488230521 100644 --- a/src/test/debuginfo/self-in-generic-default-method.rs +++ b/src/test/debuginfo/self-in-generic-default-method.rs @@ -149,3 +149,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs index 1b1765475f3..db01bc94e32 100644 --- a/src/test/pretty/block-disambig.rs +++ b/src/test/pretty/block-disambig.rs @@ -21,6 +21,8 @@ fn test2() -> int { let val = &0i; { } *val } struct S { eax: int } +impl Copy for S {} + fn test3() { let regs = &Cell::new(S {eax: 0}); match true { true => { } _ => { } } diff --git a/src/test/run-make/extern-fn-with-packed-struct/test.rs b/src/test/run-make/extern-fn-with-packed-struct/test.rs index 8d8daed1393..12d961bd59e 100644 --- a/src/test/run-make/extern-fn-with-packed-struct/test.rs +++ b/src/test/run-make/extern-fn-with-packed-struct/test.rs @@ -16,6 +16,8 @@ struct Foo { c: i8 } +impl Copy for Foo {} + #[link(name = "test", kind = "static")] extern { fn foo(f: Foo) -> Foo; diff --git a/src/test/run-make/target-specs/foo.rs b/src/test/run-make/target-specs/foo.rs index eeddd5e19a8..cab98204b17 100644 --- a/src/test/run-make/target-specs/foo.rs +++ b/src/test/run-make/target-specs/foo.rs @@ -11,6 +11,9 @@ #![feature(lang_items)] #![no_std] +#[lang="copy"] +trait Copy { } + #[lang="sized"] trait Sized { } diff --git a/src/test/run-pass/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck-univariant-enum.rs index 3d191f6c4b4..df4106c9844 100644 --- a/src/test/run-pass/borrowck-univariant-enum.rs +++ b/src/test/run-pass/borrowck-univariant-enum.rs @@ -15,6 +15,8 @@ enum newtype { newvar(int) } +impl Copy for newtype {} + pub fn main() { // Test that borrowck treats enums with a single variant diff --git a/src/test/run-pass/builtin-superkinds-in-metadata.rs b/src/test/run-pass/builtin-superkinds-in-metadata.rs index 683e7ece871..382caa83c61 100644 --- a/src/test/run-pass/builtin-superkinds-in-metadata.rs +++ b/src/test/run-pass/builtin-superkinds-in-metadata.rs @@ -19,10 +19,12 @@ use trait_superkinds_in_metadata::{RequiresCopy}; struct X<T>(T); -impl <T:Sync> RequiresShare for X<T> { } +impl<T:Copy> Copy for X<T> {} -impl <T:Sync+Send> RequiresRequiresShareAndSend for X<T> { } +impl<T:Sync> RequiresShare for X<T> { } -impl <T:Copy> RequiresCopy for X<T> { } +impl<T:Sync+Send> RequiresRequiresShareAndSend for X<T> { } + +impl<T:Copy> RequiresCopy for X<T> { } pub fn main() { } diff --git a/src/test/run-pass/cell-does-not-clone.rs b/src/test/run-pass/cell-does-not-clone.rs index c7c655b3db4..6455f1e4bb2 100644 --- a/src/test/run-pass/cell-does-not-clone.rs +++ b/src/test/run-pass/cell-does-not-clone.rs @@ -24,6 +24,8 @@ impl Clone for Foo { } } +impl Copy for Foo {} + pub fn main() { let x = Cell::new(Foo { x: 22 }); let _y = x.get(); diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index a0d35fd596b..2a9756d7714 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -14,6 +14,8 @@ use std::cmp; #[deriving(Show)] enum cat_type { tuxedo, tabby, tortoiseshell } +impl Copy for cat_type {} + impl cmp::PartialEq for cat_type { fn eq(&self, other: &cat_type) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/coherence-impl-in-fn.rs b/src/test/run-pass/coherence-impl-in-fn.rs index 51cd62677ca..df0012e07ec 100644 --- a/src/test/run-pass/coherence-impl-in-fn.rs +++ b/src/test/run-pass/coherence-impl-in-fn.rs @@ -10,6 +10,7 @@ pub fn main() { enum x { foo } + impl Copy for x {} impl ::std::cmp::PartialEq for x { fn eq(&self, other: &x) -> bool { (*self) as int == (*other) as int diff --git a/src/test/run-pass/coherence-where-clause.rs b/src/test/run-pass/coherence-where-clause.rs index faec0c50280..e0d9d569d17 100644 --- a/src/test/run-pass/coherence-where-clause.rs +++ b/src/test/run-pass/coherence-where-clause.rs @@ -28,6 +28,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait for MyType { fn get(&self) -> MyType { (*self).clone() } } diff --git a/src/test/run-pass/const-nullary-univariant-enum.rs b/src/test/run-pass/const-nullary-univariant-enum.rs index fe171a9f73d..9a1a5de9360 100644 --- a/src/test/run-pass/const-nullary-univariant-enum.rs +++ b/src/test/run-pass/const-nullary-univariant-enum.rs @@ -12,6 +12,8 @@ enum Foo { Bar = 0xDEADBEE } +impl Copy for Foo {} + static X: Foo = Foo::Bar; pub fn main() { diff --git a/src/test/run-pass/dst-struct-sole.rs b/src/test/run-pass/dst-struct-sole.rs index 04fe6d5cefd..26cb27cc653 100644 --- a/src/test/run-pass/dst-struct-sole.rs +++ b/src/test/run-pass/dst-struct-sole.rs @@ -33,6 +33,8 @@ fn foo2<T:ToBar>(x: &Fat<[T]>) { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + trait ToBar { fn to_bar(&self) -> Bar; } diff --git a/src/test/run-pass/dst-struct.rs b/src/test/run-pass/dst-struct.rs index 6b8e25e8559..bf5b300f7cf 100644 --- a/src/test/run-pass/dst-struct.rs +++ b/src/test/run-pass/dst-struct.rs @@ -49,6 +49,8 @@ fn foo3(x: &Fat<Fat<[int]>>) { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + trait ToBar { fn to_bar(&self) -> Bar; } diff --git a/src/test/run-pass/dst-trait.rs b/src/test/run-pass/dst-trait.rs index 97627309551..907c7810736 100644 --- a/src/test/run-pass/dst-trait.rs +++ b/src/test/run-pass/dst-trait.rs @@ -17,11 +17,15 @@ struct Fat<Sized? T> { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + #[deriving(PartialEq,Eq)] struct Bar1 { f: int } +impl Copy for Bar1 {} + trait ToBar { fn to_bar(&self) -> Bar; fn to_val(&self) -> int; diff --git a/src/test/run-pass/empty-tag.rs b/src/test/run-pass/empty-tag.rs index 6b780d85459..e5d11ac1adb 100644 --- a/src/test/run-pass/empty-tag.rs +++ b/src/test/run-pass/empty-tag.rs @@ -11,6 +11,8 @@ #[deriving(Show)] enum chan { chan_t, } +impl Copy for chan {} + impl PartialEq for chan { fn eq(&self, other: &chan) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/enum-discrim-width-stuff.rs b/src/test/run-pass/enum-discrim-width-stuff.rs index deb3f6b6c7c..cf8e742947d 100644 --- a/src/test/run-pass/enum-discrim-width-stuff.rs +++ b/src/test/run-pass/enum-discrim-width-stuff.rs @@ -20,6 +20,7 @@ macro_rules! check { A = 0 } static C: E = E::V; + impl Copy for E {} pub fn check() { assert_eq!(size_of::<E>(), size_of::<$t>()); assert_eq!(E::V as $t, $v as $t); diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index 829870930a4..eeda299c71f 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -18,10 +18,14 @@ type EqFn<K> = proc(K, K):'static -> bool; struct LM { resize_at: uint, size: uint } +impl Copy for LM {} + enum HashMap<K,V> { HashMap_(LM) } +impl<K,V> Copy for HashMap<K,V> {} + fn linear_map<K,V>() -> HashMap<K,V> { HashMap::HashMap_(LM{ resize_at: 32, diff --git a/src/test/run-pass/export-unexported-dep.rs b/src/test/run-pass/export-unexported-dep.rs index 3fc5310a29b..48e9d9dea22 100644 --- a/src/test/run-pass/export-unexported-dep.rs +++ b/src/test/run-pass/export-unexported-dep.rs @@ -15,6 +15,8 @@ mod foo { // not exported enum t { t1, t2, } + impl Copy for t {} + impl PartialEq for t { fn eq(&self, other: &t) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/expr-copy.rs b/src/test/run-pass/expr-copy.rs index 4a45ce66058..6e9ba4f8f41 100644 --- a/src/test/run-pass/expr-copy.rs +++ b/src/test/run-pass/expr-copy.rs @@ -15,6 +15,8 @@ fn f(arg: &mut A) { struct A { a: int } +impl Copy for A {} + pub fn main() { let mut x = A {a: 10}; f(&mut x); diff --git a/src/test/run-pass/expr-if-struct.rs b/src/test/run-pass/expr-if-struct.rs index 758d726851d..c95ca3fff8c 100644 --- a/src/test/run-pass/expr-if-struct.rs +++ b/src/test/run-pass/expr-if-struct.rs @@ -16,6 +16,8 @@ struct I { i: int } +impl Copy for I {} + fn test_rec() { let rs = if true { I {i: 100} } else { I {i: 101} }; assert_eq!(rs.i, 100); @@ -24,6 +26,8 @@ fn test_rec() { #[deriving(Show)] enum mood { happy, sad, } +impl Copy for mood {} + impl PartialEq for mood { fn eq(&self, other: &mood) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/expr-match-struct.rs b/src/test/run-pass/expr-match-struct.rs index ea96005dc60..83101a3d2cc 100644 --- a/src/test/run-pass/expr-match-struct.rs +++ b/src/test/run-pass/expr-match-struct.rs @@ -15,6 +15,8 @@ // Tests for match as expressions resulting in struct types struct R { i: int } +impl Copy for R {} + fn test_rec() { let rs = match true { true => R {i: 100}, _ => panic!() }; assert_eq!(rs.i, 100); @@ -23,6 +25,8 @@ fn test_rec() { #[deriving(Show)] enum mood { happy, sad, } +impl Copy for mood {} + impl PartialEq for mood { fn eq(&self, other: &mood) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/exterior.rs b/src/test/run-pass/exterior.rs index e95c2034131..2ca5f430a2a 100644 --- a/src/test/run-pass/exterior.rs +++ b/src/test/run-pass/exterior.rs @@ -13,6 +13,8 @@ use std::cell::Cell; struct Point {x: int, y: int, z: int} +impl Copy for Point {} + fn f(p: &Cell<Point>) { assert!((p.get().z == 12)); p.set(Point {x: 10, y: 11, z: 13}); diff --git a/src/test/run-pass/extern-pass-TwoU16s.rs b/src/test/run-pass/extern-pass-TwoU16s.rs index 6161d31c4a9..2b80a404036 100644 --- a/src/test/run-pass/extern-pass-TwoU16s.rs +++ b/src/test/run-pass/extern-pass-TwoU16s.rs @@ -16,6 +16,8 @@ pub struct TwoU16s { one: u16, two: u16 } +impl Copy for TwoU16s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; diff --git a/src/test/run-pass/extern-pass-TwoU32s.rs b/src/test/run-pass/extern-pass-TwoU32s.rs index 3e6b6502074..be4998c86fd 100644 --- a/src/test/run-pass/extern-pass-TwoU32s.rs +++ b/src/test/run-pass/extern-pass-TwoU32s.rs @@ -16,6 +16,8 @@ pub struct TwoU32s { one: u32, two: u32 } +impl Copy for TwoU32s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; diff --git a/src/test/run-pass/extern-pass-TwoU64s.rs b/src/test/run-pass/extern-pass-TwoU64s.rs index 5ad1e89425b..e8d91815bf9 100644 --- a/src/test/run-pass/extern-pass-TwoU64s.rs +++ b/src/test/run-pass/extern-pass-TwoU64s.rs @@ -16,6 +16,8 @@ pub struct TwoU64s { one: u64, two: u64 } +impl Copy for TwoU64s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; diff --git a/src/test/run-pass/extern-pass-TwoU8s.rs b/src/test/run-pass/extern-pass-TwoU8s.rs index 14ba7c80059..7aa710df800 100644 --- a/src/test/run-pass/extern-pass-TwoU8s.rs +++ b/src/test/run-pass/extern-pass-TwoU8s.rs @@ -16,6 +16,8 @@ pub struct TwoU8s { one: u8, two: u8 } +impl Copy for TwoU8s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; diff --git a/src/test/run-pass/foreign-fn-with-byval.rs b/src/test/run-pass/foreign-fn-with-byval.rs index 6a26ec44312..5d6815fc3c7 100644 --- a/src/test/run-pass/foreign-fn-with-byval.rs +++ b/src/test/run-pass/foreign-fn-with-byval.rs @@ -14,6 +14,8 @@ pub struct S { z: u64, } +impl Copy for S {} + #[link(name = "rust_test_helpers")] extern { pub fn get_x(x: S) -> u64; diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs index 89f342b4ee5..a341bfe22eb 100644 --- a/src/test/run-pass/generic-fn.rs +++ b/src/test/run-pass/generic-fn.rs @@ -14,6 +14,8 @@ fn id<T>(x: T) -> T { return x; } struct Triple {x: int, y: int, z: int} +impl Copy for Triple {} + pub fn main() { let mut x = 62; let mut y = 63; diff --git a/src/test/run-pass/guards-not-exhaustive.rs b/src/test/run-pass/guards-not-exhaustive.rs index c7f3c9d7182..b1bc40b662d 100644 --- a/src/test/run-pass/guards-not-exhaustive.rs +++ b/src/test/run-pass/guards-not-exhaustive.rs @@ -10,6 +10,8 @@ enum Q { R(Option<uint>) } +impl Copy for Q {} + fn xyzzy(q: Q) -> uint { match q { Q::R(S) if S.is_some() => { 0 } diff --git a/src/test/run-pass/guards.rs b/src/test/run-pass/guards.rs index 5bfbe4bf5a0..0157423863c 100644 --- a/src/test/run-pass/guards.rs +++ b/src/test/run-pass/guards.rs @@ -10,6 +10,8 @@ struct Pair { x: int, y: int } +impl Copy for Pair {} + pub fn main() { let a: int = match 10i { x if x < 7 => { 1i } x if x < 11 => { 2i } 10 => { 3i } _ => { 4i } }; diff --git a/src/test/run-pass/issue-12860.rs b/src/test/run-pass/issue-12860.rs index 4496a921e24..1caa04ae0b1 100644 --- a/src/test/run-pass/issue-12860.rs +++ b/src/test/run-pass/issue-12860.rs @@ -20,6 +20,8 @@ struct XYZ { z: int } +impl Copy for XYZ {} + fn main() { let mut connected = HashSet::new(); let mut border = HashSet::new(); diff --git a/src/test/run-pass/issue-19100.rs b/src/test/run-pass/issue-19100.rs index cee5c808f99..0ebd3ae8d97 100644 --- a/src/test/run-pass/issue-19100.rs +++ b/src/test/run-pass/issue-19100.rs @@ -13,6 +13,8 @@ enum Foo { Baz } +impl Copy for Foo {} + impl Foo { fn foo(&self) { match self { diff --git a/src/test/run-pass/issue-2288.rs b/src/test/run-pass/issue-2288.rs index 85dd879c830..1f371f0a1c2 100644 --- a/src/test/run-pass/issue-2288.rs +++ b/src/test/run-pass/issue-2288.rs @@ -12,10 +12,13 @@ trait clam<A> { fn chowder(&self, y: A); } + struct foo<A> { x: A, } +impl<A:Copy> Copy for foo<A> {} + impl<A> clam<A> for foo<A> { fn chowder(&self, _y: A) { } diff --git a/src/test/run-pass/issue-2633.rs b/src/test/run-pass/issue-2633.rs index a9ebfbcbf33..bc014f699c7 100644 --- a/src/test/run-pass/issue-2633.rs +++ b/src/test/run-pass/issue-2633.rs @@ -12,6 +12,8 @@ struct cat { meow: extern "Rust" fn(), } +impl Copy for cat {} + fn meow() { println!("meow") } @@ -24,6 +26,8 @@ fn cat() -> cat { struct KittyInfo {kitty: cat} +impl Copy for KittyInfo {} + // Code compiles and runs successfully if we add a + before the first arg fn nyan(kitty: cat, _kitty_info: KittyInfo) { (kitty.meow)(); diff --git a/src/test/run-pass/issue-3121.rs b/src/test/run-pass/issue-3121.rs index d0e995da5f1..9e9d611f1a3 100644 --- a/src/test/run-pass/issue-3121.rs +++ b/src/test/run-pass/issue-3121.rs @@ -13,6 +13,10 @@ enum side { mayo, catsup, vinegar } enum order { hamburger, fries(side), shake } enum meal { to_go(order), for_here(order) } +impl Copy for side {} +impl Copy for order {} +impl Copy for meal {} + fn foo(m: Box<meal>, cond: bool) { match *m { meal::to_go(_) => { } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 4e330b9a0e7..d04d8f92ac4 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -29,6 +29,8 @@ struct Point { y: int, } +impl Copy for Point {} + // Represents an offset on a canvas. (This has the same structure as a Point. // but different semantics). struct Size { @@ -36,11 +38,15 @@ struct Size { height: int, } +impl Copy for Size {} + struct Rect { top_left: Point, size: Size, } +impl Copy for Rect {} + // Contains the information needed to do shape rendering via ASCII art. struct AsciiArt { width: uint, diff --git a/src/test/run-pass/issue-3743.rs b/src/test/run-pass/issue-3743.rs index bebaad2d297..ada3e37c092 100644 --- a/src/test/run-pass/issue-3743.rs +++ b/src/test/run-pass/issue-3743.rs @@ -13,6 +13,8 @@ struct Vec2 { y: f64 } +impl Copy for Vec2 {} + // methods we want to export as methods as well as operators impl Vec2 { #[inline(always)] diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 9fbabed3a94..de6926e5512 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -19,11 +19,15 @@ pub struct Point { y: f64 } +impl Copy for Point {} + pub enum Shape { Circle(Point, f64), Rectangle(Point, Point) } +impl Copy for Shape {} + impl Shape { pub fn area(&self, sh: Shape) -> f64 { match sh { diff --git a/src/test/run-pass/issue-5688.rs b/src/test/run-pass/issue-5688.rs index 73bf375923a..0a13e001fab 100644 --- a/src/test/run-pass/issue-5688.rs +++ b/src/test/run-pass/issue-5688.rs @@ -18,7 +18,11 @@ failed to typecheck correctly. */ struct X { vec: &'static [int] } + +impl Copy for X {} + static V: &'static [X] = &[X { vec: &[1, 2, 3] }]; + pub fn main() { for &v in V.iter() { println!("{}", v.vec); diff --git a/src/test/run-pass/lang-item-public.rs b/src/test/run-pass/lang-item-public.rs index 982d4f6a0b5..81774c73c39 100644 --- a/src/test/run-pass/lang-item-public.rs +++ b/src/test/run-pass/lang-item-public.rs @@ -13,6 +13,7 @@ // ignore-windows #13361 #![no_std] +#![feature(lang_items)] extern crate "lang-item-public" as lang_lib; diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 85fa61266a3..400aab64b4c 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -38,6 +38,8 @@ const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 pub mod glfw { pub struct InputState(uint); + impl Copy for InputState {} + pub const RELEASE : InputState = InputState(0); pub const PRESS : InputState = InputState(1); pub const REPEAT : InputState = InputState(2); diff --git a/src/test/run-pass/method-self-arg-trait.rs b/src/test/run-pass/method-self-arg-trait.rs index b821c064cac..36dfe83a9eb 100644 --- a/src/test/run-pass/method-self-arg-trait.rs +++ b/src/test/run-pass/method-self-arg-trait.rs @@ -14,6 +14,8 @@ static mut COUNT: u64 = 1; struct Foo; +impl Copy for Foo {} + trait Bar { fn foo1(&self); fn foo2(self); diff --git a/src/test/run-pass/method-self-arg.rs b/src/test/run-pass/method-self-arg.rs index 3d73f34f8cf..788a25efcf9 100644 --- a/src/test/run-pass/method-self-arg.rs +++ b/src/test/run-pass/method-self-arg.rs @@ -14,6 +14,8 @@ static mut COUNT: uint = 1; struct Foo; +impl Copy for Foo {} + impl Foo { fn foo(self, x: &Foo) { unsafe { COUNT *= 2; } diff --git a/src/test/run-pass/monomorphize-abi-alignment.rs b/src/test/run-pass/monomorphize-abi-alignment.rs index 2233a5c3ea7..f5b51cd4233 100644 --- a/src/test/run-pass/monomorphize-abi-alignment.rs +++ b/src/test/run-pass/monomorphize-abi-alignment.rs @@ -19,12 +19,25 @@ */ struct S<T> { i:u8, t:T } -impl<T> S<T> { fn unwrap(self) -> T { self.t } } + +impl<T:Copy> Copy for S<T> {} + +impl<T> S<T> { + fn unwrap(self) -> T { + self.t + } +} + #[deriving(PartialEq, Show)] struct A((u32, u32)); + +impl Copy for A {} + #[deriving(PartialEq, Show)] struct B(u64); +impl Copy for B {} + pub fn main() { static Ca: S<A> = S { i: 0, t: A((13, 104)) }; static Cb: S<B> = S { i: 0, t: B(31337) }; diff --git a/src/test/run-pass/multidispatch1.rs b/src/test/run-pass/multidispatch1.rs index 76c87f5d4c5..87d188418bd 100644 --- a/src/test/run-pass/multidispatch1.rs +++ b/src/test/run-pass/multidispatch1.rs @@ -18,6 +18,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait<uint> for MyType { fn get(&self) -> uint { self.dummy } } diff --git a/src/test/run-pass/multidispatch2.rs b/src/test/run-pass/multidispatch2.rs index 13131be93c8..1aa15cc5983 100644 --- a/src/test/run-pass/multidispatch2.rs +++ b/src/test/run-pass/multidispatch2.rs @@ -27,6 +27,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait<uint> for MyType { fn get(&self) -> uint { self.dummy } } diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs index 0d1103086ae..093fd6c81cc 100644 --- a/src/test/run-pass/newtype.rs +++ b/src/test/run-pass/newtype.rs @@ -10,7 +10,14 @@ struct mytype(Mytype); -struct Mytype {compute: fn(mytype) -> int, val: int} +impl Copy for mytype {} + +struct Mytype { + compute: fn(mytype) -> int, + val: int, +} + +impl Copy for Mytype {} fn compute(i: mytype) -> int { let mytype(m) = i; diff --git a/src/test/run-pass/out-pointer-aliasing.rs b/src/test/run-pass/out-pointer-aliasing.rs index 2a44df7a1b5..5f399deb885 100644 --- a/src/test/run-pass/out-pointer-aliasing.rs +++ b/src/test/run-pass/out-pointer-aliasing.rs @@ -13,6 +13,8 @@ pub struct Foo { _f2: int, } +impl Copy for Foo {} + #[inline(never)] pub fn foo(f: &mut Foo) -> Foo { let ret = *f; diff --git a/src/test/run-pass/overloaded-autoderef-order.rs b/src/test/run-pass/overloaded-autoderef-order.rs index 0a9ac734c26..f0daf371ca7 100644 --- a/src/test/run-pass/overloaded-autoderef-order.rs +++ b/src/test/run-pass/overloaded-autoderef-order.rs @@ -15,6 +15,8 @@ struct DerefWrapper<X, Y> { y: Y } +impl<X:Copy,Y:Copy> Copy for DerefWrapper<X,Y> {} + impl<X, Y> DerefWrapper<X, Y> { fn get_x(self) -> X { self.x @@ -33,6 +35,8 @@ mod priv_test { pub y: Y } + impl<X:Copy,Y:Copy> Copy for DerefWrapperHideX<X,Y> {} + impl<X, Y> DerefWrapperHideX<X, Y> { pub fn new(x: X, y: Y) -> DerefWrapperHideX<X, Y> { DerefWrapperHideX { diff --git a/src/test/run-pass/packed-struct-vec.rs b/src/test/run-pass/packed-struct-vec.rs index c20e62351a6..59bb5678b69 100644 --- a/src/test/run-pass/packed-struct-vec.rs +++ b/src/test/run-pass/packed-struct-vec.rs @@ -19,6 +19,8 @@ struct Foo { baz: u64 } +impl Copy for Foo {} + pub fn main() { let foos = [Foo { bar: 1, baz: 2 }, .. 10]; diff --git a/src/test/run-pass/rec-tup.rs b/src/test/run-pass/rec-tup.rs index 0dc547f1a02..8adad012ec6 100644 --- a/src/test/run-pass/rec-tup.rs +++ b/src/test/run-pass/rec-tup.rs @@ -10,6 +10,8 @@ struct Point {x: int, y: int} +impl Copy for Point {} + type rect = (Point, Point); fn fst(r: rect) -> Point { let (fst, _) = r; return fst; } diff --git a/src/test/run-pass/rec.rs b/src/test/run-pass/rec.rs index b9b5cfebb0b..02fcf1ad068 100644 --- a/src/test/run-pass/rec.rs +++ b/src/test/run-pass/rec.rs @@ -13,6 +13,8 @@ struct Rect {x: int, y: int, w: int, h: int} +impl Copy for Rect {} + fn f(r: Rect, x: int, y: int, w: int, h: int) { assert_eq!(r.x, x); assert_eq!(r.y, y); diff --git a/src/test/run-pass/regions-dependent-addr-of.rs b/src/test/run-pass/regions-dependent-addr-of.rs index f074ca9a889..79f8ca48882 100644 --- a/src/test/run-pass/regions-dependent-addr-of.rs +++ b/src/test/run-pass/regions-dependent-addr-of.rs @@ -29,6 +29,8 @@ struct C { f: int } +impl Copy for C {} + fn get_v1(a: &A) -> &int { // Region inferencer must deduce that &v < L2 < L1 let foo = &a.value; // L1 diff --git a/src/test/run-pass/regions-early-bound-used-in-bound-method.rs b/src/test/run-pass/regions-early-bound-used-in-bound-method.rs index c011d11749b..5b4169a4e84 100644 --- a/src/test/run-pass/regions-early-bound-used-in-bound-method.rs +++ b/src/test/run-pass/regions-early-bound-used-in-bound-method.rs @@ -19,6 +19,8 @@ struct Box<'a> { t: &'a int } +impl<'a> Copy for Box<'a> {} + impl<'a> GetRef<'a> for Box<'a> { fn get(&self) -> &'a int { self.t diff --git a/src/test/run-pass/regions-early-bound-used-in-bound.rs b/src/test/run-pass/regions-early-bound-used-in-bound.rs index 58de2e0e20e..73eb7ca7188 100644 --- a/src/test/run-pass/regions-early-bound-used-in-bound.rs +++ b/src/test/run-pass/regions-early-bound-used-in-bound.rs @@ -19,6 +19,8 @@ struct Box<'a, T:'a> { t: &'a T } +impl<'a,T:'a> Copy for Box<'a,T> {} + impl<'a,T:Clone> GetRef<'a,T> for Box<'a,T> { fn get(&self) -> &'a T { self.t diff --git a/src/test/run-pass/regions-early-bound-used-in-type-param.rs b/src/test/run-pass/regions-early-bound-used-in-type-param.rs index 708664f33e9..622f820971f 100644 --- a/src/test/run-pass/regions-early-bound-used-in-type-param.rs +++ b/src/test/run-pass/regions-early-bound-used-in-type-param.rs @@ -19,6 +19,8 @@ struct Box<T> { t: T } +impl<T:Copy> Copy for Box<T> {} + impl<T:Clone> Get<T> for Box<T> { fn get(&self) -> T { self.t.clone() diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index e13edae330a..e10c12a6037 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -32,6 +32,9 @@ enum TypeStructure<'tcx> { TypeInt, TypeFunction(Type<'tcx>, Type<'tcx>), } + +impl<'tcx> Copy for TypeStructure<'tcx> {} + impl<'tcx> PartialEq for TypeStructure<'tcx> { fn eq(&self, other: &TypeStructure<'tcx>) -> bool { match (*self, *other) { @@ -93,6 +96,8 @@ struct NodeId { id: uint } +impl Copy for NodeId {} + type Ast<'ast> = &'ast AstStructure<'ast>; struct AstStructure<'ast> { @@ -100,12 +105,16 @@ struct AstStructure<'ast> { kind: AstKind<'ast> } +impl<'ast> Copy for AstStructure<'ast> {} + enum AstKind<'ast> { ExprInt, ExprVar(uint), ExprLambda(Ast<'ast>), } +impl<'ast> Copy for AstKind<'ast> {} + fn compute_types<'tcx,'ast>(tcx: &mut TypeContext<'tcx,'ast>, ast: Ast<'ast>) -> Type<'tcx> { diff --git a/src/test/run-pass/self-in-mut-slot-immediate-value.rs b/src/test/run-pass/self-in-mut-slot-immediate-value.rs index f2482474073..1603f7f9763 100644 --- a/src/test/run-pass/self-in-mut-slot-immediate-value.rs +++ b/src/test/run-pass/self-in-mut-slot-immediate-value.rs @@ -15,6 +15,8 @@ struct Value { n: int } +impl Copy for Value {} + impl Value { fn squared(mut self) -> Value { self.n *= self.n; diff --git a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs deleted file mode 100644 index 930364c0e22..00000000000 --- a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// Exercises a bug in the shape code that was exposed -// on x86_64: when there is an enum embedded in an -// interior record which is then itself interior to -// something else, shape calculations were off. - -#[deriving(Clone, Show)] -enum opt_span { - //hack (as opposed to option), to make `span` compile - os_none, - os_some(Box<Span>), -} - -#[deriving(Clone, Show)] -struct Span { - lo: uint, - hi: uint, - expanded_from: opt_span, -} - -#[deriving(Clone, Show)] -struct Spanned<T> { - data: T, - span: Span, -} - -type ty_ = uint; - -#[deriving(Clone, Show)] -struct Path_ { - global: bool, - idents: Vec<String> , - types: Vec<Box<ty>>, -} - -type path = Spanned<Path_>; -type ty = Spanned<ty_>; - -#[deriving(Clone, Show)] -struct X { - sp: Span, - path: path, -} - -pub fn main() { - let sp: Span = Span {lo: 57451u, hi: 57542u, expanded_from: opt_span::os_none}; - let t: Box<ty> = box Spanned { data: 3u, span: sp.clone() }; - let p_: Path_ = Path_ { - global: true, - idents: vec!("hi".to_string()), - types: vec!(t), - }; - let p: path = Spanned { data: p_, span: sp.clone() }; - let x = X { sp: sp, path: p }; - println!("{}", x.path.clone()); - println!("{}", x.clone()); -} diff --git a/src/test/run-pass/simd-generics.rs b/src/test/run-pass/simd-generics.rs index 68c210b018a..31c29b615fc 100644 --- a/src/test/run-pass/simd-generics.rs +++ b/src/test/run-pass/simd-generics.rs @@ -15,6 +15,8 @@ use std::ops; #[simd] struct f32x4(f32, f32, f32, f32); +impl Copy for f32x4 {} + fn add<T: ops::Add<T, T>>(lhs: T, rhs: T) -> T { lhs + rhs } diff --git a/src/test/run-pass/small-enum-range-edge.rs b/src/test/run-pass/small-enum-range-edge.rs index 17d647e58b5..de38a553e12 100644 --- a/src/test/run-pass/small-enum-range-edge.rs +++ b/src/test/run-pass/small-enum-range-edge.rs @@ -14,11 +14,17 @@ #[repr(u8)] enum Eu { Lu = 0, Hu = 255 } + +impl Copy for Eu {} + static CLu: Eu = Eu::Lu; static CHu: Eu = Eu::Hu; #[repr(i8)] enum Es { Ls = -128, Hs = 127 } + +impl Copy for Es {} + static CLs: Es = Es::Ls; static CHs: Es = Es::Hs; diff --git a/src/test/run-pass/struct-return.rs b/src/test/run-pass/struct-return.rs index 63574316fe5..bb06aec23f6 100644 --- a/src/test/run-pass/struct-return.rs +++ b/src/test/run-pass/struct-return.rs @@ -11,8 +11,13 @@ // ignore-lexer-test FIXME #15883 pub struct Quad { a: u64, b: u64, c: u64, d: u64 } + +impl Copy for Quad {} + pub struct Floats { a: f64, b: u8, c: f64 } +impl Copy for Floats {} + mod rustrt { use super::{Floats, Quad}; diff --git a/src/test/run-pass/structured-compare.rs b/src/test/run-pass/structured-compare.rs index 88f72932ca0..d0446d83d2e 100644 --- a/src/test/run-pass/structured-compare.rs +++ b/src/test/run-pass/structured-compare.rs @@ -13,6 +13,8 @@ #[deriving(Show)] enum foo { large, small, } +impl Copy for foo {} + impl PartialEq for foo { fn eq(&self, other: &foo) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index 7aa2ba280ac..cf53c1a912a 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -20,6 +20,8 @@ enum color { orange = 8 >> 1 } +impl Copy for color {} + impl PartialEq for color { fn eq(&self, other: &color) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/trait-coercion-generic.rs b/src/test/run-pass/trait-coercion-generic.rs index 1e241ad2278..7d924f977cb 100644 --- a/src/test/run-pass/trait-coercion-generic.rs +++ b/src/test/run-pass/trait-coercion-generic.rs @@ -18,6 +18,8 @@ struct Struct { y: int, } +impl Copy for Struct {} + impl Trait<&'static str> for Struct { fn f(&self, x: &'static str) { println!("Hi, {}!", x); diff --git a/src/test/run-pass/trait-coercion.rs b/src/test/run-pass/trait-coercion.rs index 55beebbf2bc..37d69ddfe07 100644 --- a/src/test/run-pass/trait-coercion.rs +++ b/src/test/run-pass/trait-coercion.rs @@ -19,6 +19,8 @@ struct Struct { y: int, } +impl Copy for Struct {} + impl Trait for Struct { fn f(&self) { println!("Hi!"); diff --git a/src/test/run-pass/typeclasses-eq-example-static.rs b/src/test/run-pass/typeclasses-eq-example-static.rs index a5547c0eea9..6b00a8b5c2d 100644 --- a/src/test/run-pass/typeclasses-eq-example-static.rs +++ b/src/test/run-pass/typeclasses-eq-example-static.rs @@ -18,8 +18,11 @@ trait Equal { fn isEq(a: &Self, b: &Self) -> bool; } +#[deriving(Clone)] enum Color { cyan, magenta, yellow, black } +impl Copy for Color {} + impl Equal for Color { fn isEq(a: &Color, b: &Color) -> bool { match (*a, *b) { @@ -32,6 +35,7 @@ impl Equal for Color { } } +#[deriving(Clone)] enum ColorTree { leaf(Color), branch(Box<ColorTree>, Box<ColorTree>) @@ -40,9 +44,12 @@ enum ColorTree { impl Equal for ColorTree { fn isEq(a: &ColorTree, b: &ColorTree) -> bool { match (a, b) { - (&leaf(x), &leaf(y)) => { Equal::isEq(&x, &y) } + (&leaf(ref x), &leaf(ref y)) => { + Equal::isEq(&(*x).clone(), &(*y).clone()) + } (&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => { - Equal::isEq(&**l1, &**l2) && Equal::isEq(&**r1, &**r2) + Equal::isEq(&(**l1).clone(), &(**l2).clone()) && + Equal::isEq(&(**r1).clone(), &(**r2).clone()) } _ => { false } } diff --git a/src/test/run-pass/typeclasses-eq-example.rs b/src/test/run-pass/typeclasses-eq-example.rs index 21b9c774e8c..e4b7d2eb60b 100644 --- a/src/test/run-pass/typeclasses-eq-example.rs +++ b/src/test/run-pass/typeclasses-eq-example.rs @@ -17,8 +17,11 @@ trait Equal { fn isEq(&self, a: &Self) -> bool; } +#[deriving(Clone)] enum Color { cyan, magenta, yellow, black } +impl Copy for Color {} + impl Equal for Color { fn isEq(&self, a: &Color) -> bool { match (*self, *a) { @@ -31,6 +34,7 @@ impl Equal for Color { } } +#[deriving(Clone)] enum ColorTree { leaf(Color), branch(Box<ColorTree>, Box<ColorTree>) @@ -39,9 +43,9 @@ enum ColorTree { impl Equal for ColorTree { fn isEq(&self, a: &ColorTree) -> bool { match (self, a) { - (&leaf(x), &leaf(y)) => { x.isEq(&y) } + (&leaf(ref x), &leaf(ref y)) => { x.isEq(&(*y).clone()) } (&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => { - (&**l1).isEq(&**l2) && (&**r1).isEq(&**r2) + (*l1).isEq(&(**l2).clone()) && (*r1).isEq(&(**r2).clone()) } _ => { false } } diff --git a/src/test/run-pass/ufcs-explicit-self.rs b/src/test/run-pass/ufcs-explicit-self.rs index b96820eee14..b6b9fb67f90 100644 --- a/src/test/run-pass/ufcs-explicit-self.rs +++ b/src/test/run-pass/ufcs-explicit-self.rs @@ -12,6 +12,8 @@ struct Foo { f: int, } +impl Copy for Foo {} + impl Foo { fn foo(self: Foo, x: int) -> int { self.f + x @@ -28,6 +30,8 @@ struct Bar<T> { f: T, } +impl<T:Copy> Copy for Bar<T> {} + impl<T> Bar<T> { fn foo(self: Bar<T>, x: int) -> int { x diff --git a/src/test/run-pass/unboxed-closures-monomorphization.rs b/src/test/run-pass/unboxed-closures-monomorphization.rs index 43fb4b296cc..cd97fd96fa3 100644 --- a/src/test/run-pass/unboxed-closures-monomorphization.rs +++ b/src/test/run-pass/unboxed-closures-monomorphization.rs @@ -30,6 +30,9 @@ fn main(){ #[deriving(Show, PartialEq)] struct Foo(uint, &'static str); + + impl Copy for Foo {} + let x = Foo(42, "forty-two"); let f = bar(x); assert_eq!(f.call_once(()), x); |
