Skip to content

Commit 7880bb8

Browse files
committed
Accept empty enums if they implement Default
1 parent 0c78d9d commit 7880bb8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/input.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ impl<'a> Input<'a> {
4848
.map(|variant| Data::from_variant(ident, &derive_wheres, variant))
4949
.collect::<Result<Vec<Data>>>()?;
5050

51-
// Empty enums aren't allowed.
52-
if variants.iter().all(|variant| match variant.fields() {
53-
Either::Left(fields) => fields.fields.is_empty(),
54-
Either::Right(_) => true,
55-
}) {
56-
return Err(Error::item_empty(span));
57-
}
58-
5951
// Find if a default option is specified on a variant.
6052
let mut found_default = false;
6153

@@ -80,6 +72,15 @@ impl<'a> Input<'a> {
8072
return Err(Error::default_missing(span));
8173
}
8274

75+
// Empty enums aren't allowed unless they implement `Default`.
76+
if !found_default
77+
&& variants.iter().all(|variant| match variant.fields() {
78+
Either::Left(fields) => fields.fields.is_empty(),
79+
Either::Right(_) => true,
80+
}) {
81+
return Err(Error::item_empty(span));
82+
}
83+
8384
Item::Enum { ident, variants }
8485
}
8586
syn::Data::Union(data) => {

0 commit comments

Comments
 (0)