Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement specialised clone_from via #[derive(Clone)] #27939

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Add/extend tests for deriving Clone
  • Loading branch information
Diggsey committed Aug 22, 2015
commit e175c296f4f4dd36e924ca782709e837c9484233
7 changes: 6 additions & 1 deletion src/test/run-pass/deriving-clone-enum.rs
Original file line number Diff line number Diff line change
@@ -18,5 +18,10 @@ enum E {
}

pub fn main() {
let _ = E::A.clone();
let mut foo = E::A.clone();

// Test both code-paths of clone_from (same variant/different variant)
foo.clone_from(&E::A);
foo.clone_from(&E::B(()));
foo.clone_from(&E::B(()));
}
7 changes: 6 additions & 1 deletion src/test/run-pass/deriving-clone-generic-enum.rs
Original file line number Diff line number Diff line change
@@ -18,5 +18,10 @@ enum E<T,U> {
}

pub fn main() {
let _ = E::A::<isize, isize>(1).clone();
let mut foo = E::A::<isize, isize>(1).clone();

// Test both code-paths of clone_from (same variant/different variant)
foo.clone_from(&E::A(32));
foo.clone_from(&E::B(1, 2));
foo.clone_from(&E::B(3, 4));
}
3 changes: 2 additions & 1 deletion src/test/run-pass/deriving-clone-generic-struct.rs
Original file line number Diff line number Diff line change
@@ -18,5 +18,6 @@ struct S<T> {
}

pub fn main() {
let _ = S { foo: (), bar: (), baz: 1 }.clone();
let mut foo = S { foo: (), bar: (), baz: 1 }.clone();
foo.clone_from(&S { foo: (), bar: (), baz: 31 });
}
3 changes: 2 additions & 1 deletion src/test/run-pass/deriving-clone-generic-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -14,5 +14,6 @@
struct S<T>(T, ());

pub fn main() {
let _ = S(1, ()).clone();
let mut foo = S(1, ()).clone();
foo.clone_from(&S(32, ()));
}