summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorEric Seppanen <eds@reric.net>2021-11-07 13:41:19 -0800
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-11-26 02:33:39 +0100
commit0a24ab3a304e7d8f0a08918413145667cabb9aaa (patch)
tree2c8e1cc91f51c4f87e8cb5ea621049e67e00357a /src/codegen/mod.rs
parent2aed6b0216805e27228ed39988ffe1a1ffd7e940 (diff)
allow custom derives on enums
Custom derives are just as useful on enums as they are on structs; not supporting this was an oversight. Adds a test that will fail to compile if the custom derive doesn't work on enums. This test fails without the codegen fix.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 69dde2c5..b703a106 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3014,6 +3014,16 @@ impl CodeGenerator for Enum {
derives.push(derive);
}
}
+
+ // The custom derives callback may return a list of derive attributes;
+ // add them to the end of the list.
+ let custom_derives;
+ if let Some(cb) = &ctx.options().parse_callbacks {
+ custom_derives = cb.add_derives(&name);
+ // In most cases this will be a no-op, since custom_derives will be empty.
+ derives.extend(custom_derives.iter().map(|s| s.as_str()));
+ };
+
attrs.push(attributes::derives(&derives));
}