diff options
author | Yamakaky <yamakaky@yamaworld.fr> | 2016-03-11 15:19:44 +0100 |
---|---|---|
committer | Yamakaky <yamakaky@yamaworld.fr> | 2016-03-11 15:19:44 +0100 |
commit | af4ab06657ae224bd2e7bec8efdbef3aa924f34c (patch) | |
tree | c24dd08c48f1ca60adb5bc3af28259e083c48c1d /src | |
parent | 08a32d5276afa7c120af3ce83ba3e32d59503e68 (diff) |
derive(Debug) on unions.
Related #282
Diffstat (limited to 'src')
-rw-r--r-- | src/gen.rs | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -671,7 +671,22 @@ fn cunion_to_rs(ctx: &mut GenCtx, name: String, derive_debug: bool, layout: Layo empty_generics() ); let union_id = rust_type_id(ctx, name.clone()); - let union_attrs = vec!(mk_repr_attr(ctx, layout), mk_deriving_copy_attr(ctx, false)); + let union_attrs = { + let mut attrs = vec!(mk_repr_attr(ctx, layout), mk_deriving_copy_attr(ctx, false)); + if derive_debug { + let can_derive_debug = members.iter() + .all(|member| match member { + &CompMember::Field(ref f) | + &CompMember::CompField(_, ref f) => f.ty.can_derive_debug(), + _ => true + }); + if can_derive_debug { + attrs.push(mk_deriving_debug_attr(ctx)) + } + } + attrs + }; + let union_def = mk_item(ctx, union_id, def, ast::Visibility::Public, union_attrs); let union_impl = ast::ItemKind::Impl( |