Skip to content

Commit 6d7596e

Browse files
committed
fix :
- clippy beta - better compile error (+related doc and test)
1 parent 7dd1a93 commit 6d7596e

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

guide/src/class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ enum BadSubclass {
11831183

11841184
An enum is complex if it has any non-unit (struct or tuple) variants.
11851185

1186-
Currently PyO3 supports only struct and tuple variants in a complex enum. Support for unit variants is planned.
1186+
PyO3 supports only struct and tuple variants in a complex enum. Unit variants aren't supported at present (the recommendation is to use an empty tuple enum instead).
11871187

11881188
PyO3 adds a class attribute for each variant, which may be used to construct values and in match patterns. PyO3 also provides getter methods for all fields of each variant.
11891189

pyo3-macros-backend/src/pyclass.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl<'a> PyClassComplexEnum<'a> {
505505
Fields::Unit => {
506506
bail_spanned!(variant.span() => format!(
507507
"Unit variant `{ident}` is not yet supported in a complex enum\n\
508-
= help: change to a struct variant with no fields: `{ident} {{ }}`\n\
508+
= help: change to an empty tuple variant instead: `{ident}()`\n\
509509
= note: the enum is complex because of non-unit variant `{witness}`",
510510
ident=ident, witness=witness))
511511
}
@@ -530,8 +530,7 @@ impl<'a> PyClassComplexEnum<'a> {
530530
let fields = types
531531
.unnamed
532532
.iter()
533-
.enumerate()
534-
.map(|(_i, field)| PyClassEnumVariantUnnamedField {
533+
.map(|field| PyClassEnumVariantUnnamedField {
535534
ty: &field.ty,
536535
span: field.span(),
537536
})

tests/ui/invalid_pyclass_enum.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error: #[pyclass] can't be used on enums without any variants
1717
| ^^
1818

1919
error: Unit variant `UnitVariant` is not yet supported in a complex enum
20-
= help: change to a struct variant with no fields: `UnitVariant { }`
20+
= help: change to an empty tuple variant instead: `UnitVariant()`
2121
= note: the enum is complex because of non-unit variant `StructVariant`
2222
--> tests/ui/invalid_pyclass_enum.rs:21:5
2323
|

0 commit comments

Comments
 (0)