Merge pull request #2018 from b05902132/derive-enum
Let #[pyclass] reject empty enums.
This commit is contained in:
commit
af27fd373b
|
@ -386,6 +386,9 @@ pub fn build_py_enum(
|
||||||
args: PyClassArgs,
|
args: PyClassArgs,
|
||||||
method_type: PyClassMethodsType,
|
method_type: PyClassMethodsType,
|
||||||
) -> syn::Result<TokenStream> {
|
) -> syn::Result<TokenStream> {
|
||||||
|
if enum_.variants.is_empty() {
|
||||||
|
bail_spanned!(enum_.brace_token.span => "Empty enums can't be #[pyclass].");
|
||||||
|
}
|
||||||
let variants: Vec<PyClassEnumVariant> = enum_
|
let variants: Vec<PyClassEnumVariant> = enum_
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -12,4 +12,7 @@ enum NotDrivedClass {
|
||||||
y,
|
y,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyclass]
|
||||||
|
enum NoEmptyEnum {}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -9,3 +9,9 @@ error: enums cannot extend from other classes
|
||||||
|
|
|
|
||||||
9 | #[pyclass(extends = PyList)]
|
9 | #[pyclass(extends = PyList)]
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: Empty enums can't be #[pyclass].
|
||||||
|
--> tests/ui/invalid_pyclass_enum.rs:16:18
|
||||||
|
|
|
||||||
|
16 | enum NoEmptyEnum {}
|
||||||
|
| ^^
|
||||||
|
|
Loading…
Reference in New Issue