librustc: Add a lint mode for unnecessary copy and remove a bunch of them.

This commit is contained in:
Patrick Walton 2013-06-27 17:41:35 -07:00
parent 8c082658be
commit b4e674f6e6
59 changed files with 256 additions and 235 deletions

View file

@ -89,7 +89,7 @@ pub fn main() {
let nyan : cat = cat(0u, 2, ~"nyan");
let whitefang : dog = dog();
annoy_neighbors(@(copy nyan) as @noisy);
annoy_neighbors(@(copy whitefang) as @noisy);
annoy_neighbors(@whitefang as @noisy);
assert_eq!(nyan.meow_count(), 10u);
assert_eq!(*whitefang.volume, 1);
}

View file

@ -50,7 +50,7 @@ struct A { a: @int }
fn thing(x: A) -> thing {
thing {
x: copy x
x: x
}
}

View file

@ -21,7 +21,7 @@ pub fn main() {
f(&mut x);
assert_eq!(x.a, 100);
x.a = 20;
let mut y = copy x;
let mut y = x;
f(&mut y);
assert_eq!(x.a, 20);
}

View file

@ -14,9 +14,9 @@ fn main() {
println(v[3].to_str());
println(v[4].to_str());
let v: @mut [int] = @mut [ 3, ..5 ];
println((copy v[0]).to_str());
println((copy v[1]).to_str());
println((copy v[2]).to_str());
println((copy v[3]).to_str());
println((copy v[4]).to_str());
println((v[0]).to_str());
println((v[1]).to_str());
println((v[2]).to_str());
println((v[3]).to_str());
println((v[4]).to_str());
}

View file

@ -18,7 +18,7 @@ fn f(p: @mut Point) { assert!((p.z == 12)); p.z = 13; assert!((p.z == 13)); }
pub fn main() {
let a: Point = Point {x: 10, y: 11, z: 12};
let b: @mut Point = @mut copy a;
let b: @mut Point = @mut a;
assert_eq!(b.z, 12);
f(b);
assert_eq!(a.z, 12);

View file

@ -27,5 +27,5 @@ fn nyan(kitty: cat, _kitty_info: KittyInfo) {
pub fn main() {
let mut kitty = cat();
nyan(copy kitty, KittyInfo {kitty: copy kitty});
nyan(kitty, KittyInfo {kitty: kitty});
}

View file

@ -10,7 +10,7 @@
fn double<T:Copy>(a: T) -> ~[T] { return ~[copy a] + ~[a]; }
fn double_int(a: int) -> ~[int] { return ~[copy a] + ~[a]; }
fn double_int(a: int) -> ~[int] { return ~[a] + ~[a]; }
pub fn main() {
let mut d = double(1);

View file

@ -16,6 +16,6 @@ struct Refs { refs: ~[int], n: int }
pub fn main() {
let e = @mut Refs{refs: ~[], n: 0};
let f: @fn() = || error!(copy e.n);
let f: @fn() = || error!(e.n);
e.refs.push(1);
}

View file

@ -43,7 +43,7 @@ fn runtest2(f: extern fn(), frame_backoff: u32, last_stk: *u8) -> u32 {
// We switched stacks, go back and try to hit the dynamic linker
frame_backoff
} else {
let frame_backoff = runtest2(copy f, frame_backoff, curr_stk);
let frame_backoff = runtest2(f, frame_backoff, curr_stk);
if frame_backoff > 1u32 {
frame_backoff - 1u32
} else if frame_backoff == 1u32 {

View file

@ -36,7 +36,6 @@ impl<T> E<T> {
macro_rules! check_option {
($e:expr: $T:ty) => {{
// FIXME #6000: remove the copy
check_option!(copy $e: $T, |ptr| assert!(*ptr == $e));
}};
($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
@ -49,7 +48,6 @@ macro_rules! check_option {
macro_rules! check_fancy {
($e:expr: $T:ty) => {{
// FIXME #6000: remove the copy
check_fancy!(copy $e: $T, |ptr| assert!(*ptr == $e));
}};
($e:expr: $T:ty, |$v:ident| $chk:expr) => {{