summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cann <shum@canndrew.org>2014-12-13 17:30:16 +0800
committerAndrew Cann <shum@canndrew.org>2014-12-13 17:30:16 +0800
commit889f64a7fa9b90fd8d08375dd903b4d7ea7d7bf8 (patch)
tree1e604d1da9f732955f592f4b3414e5b059cd8638
parentae2651f261eba2966d8f08901311e0140f85c838 (diff)
Add #[deriving(Copy)] to rustified structs and unions
-rw-r--r--src/gen.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/gen.rs b/src/gen.rs
index cf1d2ad7..6ddb3472 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -492,7 +492,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: String, fields: Vec<FieldInfo>) -> P<as
let id = rust_type_id(ctx, name);
return P(ast::Item { ident: ctx.ext_cx.ident_of(id.as_slice()),
- attrs: vec!(mk_repr_attr(ctx)),
+ attrs: vec!(mk_repr_attr(ctx), mk_deriving_copy_attr(ctx)),
id: ast::DUMMY_NODE_ID,
node: def,
vis: ast::Public,
@@ -562,7 +562,7 @@ fn cunion_to_rs(ctx: &mut GenCtx, name: String, layout: Layout, fields: Vec<Fiel
empty_generics()
);
let union_id = rust_type_id(ctx, name);
- let union_attrs = vec!(mk_repr_attr(ctx));
+ let union_attrs = vec!(mk_repr_attr(ctx), mk_deriving_copy_attr(ctx));
let union_def = mk_item(ctx, union_id, def, ast::Public, union_attrs);
let expr = quote_expr!(
@@ -699,6 +699,20 @@ fn mk_repr_attr(ctx: &mut GenCtx) -> ast::Attribute {
})
}
+fn mk_deriving_copy_attr(ctx: &mut GenCtx) -> ast::Attribute {
+ let attr_val = P(respan(ctx.span, ast::MetaList(
+ to_intern_str(ctx, "deriving".to_string()),
+ vec!(P(respan(ctx.span, ast::MetaWord(to_intern_str(ctx, "Copy".to_string())))))
+ )));
+
+ respan(ctx.span, ast::Attribute_ {
+ id: mk_attr_id(),
+ style: ast::AttrOuter,
+ value: attr_val,
+ is_sugared_doc: false
+ })
+}
+
fn cvar_to_rs(ctx: &mut GenCtx, name: String,
ty: &Type,
is_const: bool) -> P<ast::ForeignItem> {