Skip to content

Commit fa6f440

Browse files
Jorge AparicioYamakaky
Jorge Aparicio
authored andcommitted
produce valid univariant enums
Instead of generating a enum like this: ``` pub enum Enum_CUipcMem_flags_enum { CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS = 1, } ``` Which is a compiler error because repr can't be used with univariant enums. See rust-lang/rust#10292 We generate a two variant enum with a dummy variant. ``` pub enum Enum_CUipcMem_flags_enum { CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS = 1, __DUMMY, } ``` Which is the recommend workaround to the previous compiler error. closes rust-lang#255
1 parent 782156e commit fa6f440

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/gen.rs

+10
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,16 @@ fn cenum_to_rs(ctx: &mut GenCtx, name: String, kind: IKind, enum_items: &[EnumIt
745745
}));
746746
}
747747

748+
// for univariant enums, we add a dummy variant to avoid rust-lang/rust#10292
749+
if enum_items.len() == 1 {
750+
variants.push(P(respan(ctx.span, ast::Variant_ {
751+
name: ctx.ext_cx.ident_of("__DUMMY"),
752+
attrs: vec![],
753+
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
754+
disr_expr: None,
755+
})));
756+
}
757+
748758
let enum_repr = InternedString::new(enum_kind_to_rust_type_name(kind));
749759

750760
let repr_arg = ctx.ext_cx.meta_word(ctx.span, enum_repr);

0 commit comments

Comments
 (0)