@@ -20,8 +20,8 @@ use internals::ast::{Container, Data, Field, Style};
20
20
// 8 | enum EnumDef { V }
21
21
// | ^
22
22
//
23
- pub fn pretend_used ( cont : & Container ) -> TokenStream {
24
- let pretend_fields = pretend_fields_used ( cont) ;
23
+ pub fn pretend_used ( cont : & Container , is_packed : bool ) -> TokenStream {
24
+ let pretend_fields = pretend_fields_used ( cont, is_packed ) ;
25
25
let pretend_variants = pretend_variants_used ( cont) ;
26
26
27
27
quote ! {
@@ -48,7 +48,7 @@ pub fn pretend_used(cont: &Container) -> TokenStream {
48
48
// The `ref` is important in case the user has written a Drop impl on their
49
49
// type. Rust does not allow destructuring a struct or enum that has a Drop
50
50
// impl.
51
- fn pretend_fields_used ( cont : & Container ) -> TokenStream {
51
+ fn pretend_fields_used ( cont : & Container , is_packed : bool ) -> TokenStream {
52
52
let type_ident = & cont. ident ;
53
53
let ( _, ty_generics, _) = cont. generics . split_for_impl ( ) ;
54
54
@@ -58,14 +58,14 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
58
58
. filter_map ( |variant| match variant. style {
59
59
Style :: Struct => {
60
60
let variant_ident = & variant. ident ;
61
- let pat = struct_pattern ( & variant. fields ) ;
61
+ let pat = struct_pattern ( & variant. fields , is_packed ) ;
62
62
Some ( quote ! ( #type_ident:: #variant_ident #pat) )
63
63
}
64
64
_ => None ,
65
65
} )
66
66
. collect :: < Vec < _ > > ( ) ,
67
67
Data :: Struct ( Style :: Struct , fields) => {
68
- let pat = struct_pattern ( fields) ;
68
+ let pat = struct_pattern ( fields, is_packed ) ;
69
69
vec ! [ quote!( #type_ident #pat) ]
70
70
}
71
71
Data :: Struct ( _, _) => {
@@ -132,9 +132,14 @@ fn pretend_variants_used(cont: &Container) -> TokenStream {
132
132
quote ! ( #( #cases) * )
133
133
}
134
134
135
- fn struct_pattern ( fields : & [ Field ] ) -> TokenStream {
135
+ fn struct_pattern ( fields : & [ Field ] , is_packed : bool ) -> TokenStream {
136
136
let members = fields. iter ( ) . map ( |field| & field. member ) ;
137
137
let placeholders =
138
138
( 0 ..fields. len ( ) ) . map ( |i| Ident :: new ( & format ! ( "__v{}" , i) , Span :: call_site ( ) ) ) ;
139
- quote ! ( { #( #members: ref #placeholders) , * } )
139
+ let take_reference = if is_packed {
140
+ None
141
+ } else {
142
+ Some ( quote ! ( ref) )
143
+ } ;
144
+ quote ! ( { #( #members: #take_reference #placeholders) , * } )
140
145
}
0 commit comments