about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-09 11:54:44 -0800
committerbors <bors@rust-lang.org>2013-03-09 11:54:44 -0800
commit1cde7e6bc266af836e0695be7282257838eee05a (patch)
treef36c27cceceb7264493a4c49acbaff89908307e6
parenta5fae1dac71567b3c9b455e69c1fe74e46945f4d (diff)
parentbef5396af68b5a7d181bef70a920a910416d9094 (diff)
downloadrust-1cde7e6bc266af836e0695be7282257838eee05a.tar.gz
rust-1cde7e6bc266af836e0695be7282257838eee05a.zip
auto merge of #5294 : apasel422/rust/clone, r=nikomatsakis
This makes `#[deriving_clone]` useful.

I wasn't sure if a macro was the right way to do this, but it seems more maintainable than a series of repetitive `impl`s.
-rw-r--r--src/libcore/clone.rs28
-rw-r--r--src/test/run-pass/deriving-clone-struct.rs22
2 files changed, 47 insertions, 3 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs
index 6580ce55ddd..297c4438039 100644
--- a/src/libcore/clone.rs
+++ b/src/libcore/clone.rs
@@ -19,3 +19,31 @@ impl Clone for () {
     #[inline(always)]
     fn clone(&self) -> () { () }
 }
+
+macro_rules! clone_impl(
+    ($t:ty) => {
+        impl Clone for $t {
+            #[inline(always)]
+            fn clone(&self) -> $t { *self }
+        }
+    }
+)
+
+clone_impl!(int)
+clone_impl!(i8)
+clone_impl!(i16)
+clone_impl!(i32)
+clone_impl!(i64)
+
+clone_impl!(uint)
+clone_impl!(u8)
+clone_impl!(u16)
+clone_impl!(u32)
+clone_impl!(u64)
+
+clone_impl!(float)
+clone_impl!(f32)
+clone_impl!(f64)
+
+clone_impl!(bool)
+clone_impl!(char)
diff --git a/src/test/run-pass/deriving-clone-struct.rs b/src/test/run-pass/deriving-clone-struct.rs
index 2f371c8920b..07830e7ee09 100644
--- a/src/test/run-pass/deriving-clone-struct.rs
+++ b/src/test/run-pass/deriving-clone-struct.rs
@@ -1,8 +1,24 @@
 #[deriving_clone]
 struct S {
-    foo: (),
-    bar: ()
+    _int: int,
+    _i8: i8,
+    _i16: i16,
+    _i32: i32,
+    _i64: i64,
+
+    _uint: uint,
+    _u8: u8,
+    _u16: u16,
+    _u32: u32,
+    _u64: u64,
+
+    _float: float,
+    _f32: f32,
+    _f64: f64,
+
+    _bool: bool,
+    _char: char,
+    _nil: ()
 }
 
 fn main() {}
-