summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2020-10-13 11:06:24 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2020-10-16 12:12:17 +0200
commita467d3efc6f9fbe2e811468adbaa3687a9938b0d (patch)
tree72d373f43c3152d31ede0193aa62da35ea43c75d /src
parente0961491034b243cc23c40619da732cd5680f4c6 (diff)
codegen: Allow to not derive Debug on enums.
Fixes #1899. This code predated all the derive machinery, and always hardcoded its derives. We could avoid hard-coding the other traits, but those seem usually-useful, so leave them there for backwards compat for now.
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 44ad5cb2..91acf5b0 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2840,17 +2840,17 @@ impl CodeGenerator for Enum {
}
if !variation.is_const() {
- let mut derives =
- vec!["Debug", "Copy", "Clone", "PartialEq", "Eq", "Hash"];
-
- if item.can_derive_partialord(ctx) {
- derives.push("PartialOrd");
- }
-
- if item.can_derive_ord(ctx) {
- derives.push("Ord");
- }
-
+ let mut derives = derives_of_item(item, ctx);
+ // For backwards compat, enums always derive Clone/Eq/PartialEq/Hash, even
+ // if we don't generate those by default.
+ derives.insert(
+ DerivableTraits::CLONE |
+ DerivableTraits::COPY |
+ DerivableTraits::HASH |
+ DerivableTraits::PARTIAL_EQ |
+ DerivableTraits::EQ,
+ );
+ let derives: Vec<_> = derives.into();
attrs.push(attributes::derives(&derives));
}