Skip to content

Commit 199e0c9

Browse files
pzhan9facebook-github-bot
authored andcommitted
Fix a Bind/Unbind macro bug (#513)
Summary: Pull Request resolved: #513 The current implementation adds an extra `,` for empty struct variant in enum: ``` enum MyEnum { EmptyStruct {}, } ``` which made the generate code uncompilable. This diff fixes that. Reviewed By: highker Differential Revision: D78184202 fbshipit-source-id: 2b5c82d3632888e8f29ac4e2ea7f2f546191c1ef
1 parent cd9f3bc commit 199e0c9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

hyperactor_macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ where
16001600

16011601
Ok(match &variant.fields {
16021602
Fields::Named(_) => {
1603-
quote! { Self::#name { #(#field_accessors),*, } => { #(#items)* } }
1603+
quote! { Self::#name { #(#field_accessors),* } => { #(#items)* } }
16041604
}
16051605
Fields::Unnamed(_) => {
16061606
quote! { Self::#name( #(#field_accessors),* ) => { #(#items)* } }

hyperactor_macros/tests/castable.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ use hyperactor::message::Unbind;
1717
use serde::Deserialize;
1818
use serde::Serialize;
1919

20+
#[derive(Bind, Unbind)]
21+
struct MyUnitStruct;
22+
23+
#[derive(Bind, Unbind)]
24+
struct EmptyNamedStruct {}
25+
26+
#[derive(Bind, Unbind)]
27+
struct EmptyUnamedStruct();
28+
2029
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Named)]
2130
struct MyReply(String);
2231

@@ -46,6 +55,8 @@ struct MyGenericStruct<'a, A: Bind + Unbind, B>(#[binding(include)] A, &'a B, A)
4655
#[derive(Clone, Debug, PartialEq, Bind, Unbind)]
4756
enum MyEnum {
4857
Unit,
58+
EmptyStruct {},
59+
EmptyTuple(),
4960
NoopTuple(u64, bool),
5061
NoopStruct {
5162
field0: u64,
@@ -72,6 +83,8 @@ enum MyEnum {
7283
#[derive(Clone, Debug, PartialEq, Bind, Unbind)]
7384
enum MyGenericEnum<'a, A: Bind + Unbind, B> {
7485
Unit,
86+
EmptyStruct {},
87+
EmptyTuple(),
7588
Tuple(#[binding(include)] A, &'a B, A),
7689
}
7790

0 commit comments

Comments
 (0)