Skip to content

Commit 8c1342a

Browse files
committed
Fix parse errors in procedural derive for enums
Wow this is why I should actually unit test stuff -_-
1 parent 6988d22 commit 8c1342a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

libs/derive/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,22 +554,22 @@ fn impl_trace(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream, Er
554554
)
555555
},
556556
};
557-
quote!(ref mut #ident)
557+
quote!(#ident)
558558
}
559559
);
560560
let pattern = match variant.fields {
561561
Fields::Named(ref fields) => {
562562
let names = fields.named.iter()
563563
.map(|field| field.ident.as_ref().unwrap());
564-
quote!({ #(#names,)* })
564+
quote!({ #(ref mut #names,)* })
565565
},
566566
Fields::Unnamed(ref fields) => {
567567
let names = (0..fields.unnamed.len())
568568
.map(|index| Ident::new(
569569
&format!("field{}", index),
570570
Span::call_site()
571571
));
572-
quote!(#(#names,)*)
572+
quote!(( #(ref mut #names,)* ))
573573
},
574574
Fields::Unit => quote!(),
575575
};
@@ -783,6 +783,7 @@ fn add_trait_bounds(
783783
}
784784

785785
fn debug_derive(key: &str, message: &dyn Display, value: &dyn Display) {
786+
// TODO: Use proc_macro::tracked_env::var
786787
match ::std::env::var_os("DEBUG_DERIVE") {
787788
Some(var) if var == "*" ||
788789
var.to_string_lossy().contains(key) => {

libs/derive/tests/basic.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ pub struct BasicCopy<'gc, Id: CollectorId> {
1818
basic: Option<Gc<'gc, Basic<'gc, Id>, Id>>
1919
}
2020

21+
22+
#[derive(Copy, Clone, Trace)]
23+
#[zerogc(copy, ignore_params(Id))]
24+
pub enum BasicEnum<'gc, Id: CollectorId> {
25+
Unit,
26+
Tuple(i32),
27+
First {
28+
all: i32
29+
},
30+
Second {
31+
you: Gc<'gc, String, Id>,
32+
need: bool
33+
},
34+
Third {
35+
is: (),
36+
love: Gc<'gc, BasicEnum<'gc, Id>, Id>
37+
},
38+
Fifth(
39+
Gc<'gc, BasicEnum<'gc, Id>, Id>,
40+
Gc<'gc, Basic<'gc, Id>, Id>
41+
)
42+
}
43+
2144
fn assert_copy<T: Copy>() {}
2245
fn assert_null_trace<T: NullTrace>() {}
2346
fn check_id<'gc, Id: CollectorId>() {

0 commit comments

Comments
 (0)