@@ -10,7 +10,7 @@ extern crate syn;
10
10
extern crate synstructure;
11
11
12
12
#[ cfg( not( test) ) ]
13
- #[ proc_macro_derive( HeapSizeOf ) ]
13
+ #[ proc_macro_derive( HeapSizeOf , attributes ( ignore_heap_size_of ) ) ]
14
14
pub fn expand_token_stream ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
15
15
expand_string ( & input. to_string ( ) ) . parse ( ) . unwrap ( )
16
16
}
@@ -20,18 +20,16 @@ fn expand_string(input: &str) -> String {
20
20
21
21
let style = synstructure:: BindStyle :: Ref . into ( ) ;
22
22
let match_body = synstructure:: each_field ( & mut type_, & style, |binding| {
23
- let mut ignore = false ;
24
- binding. field . attrs . retain ( |attr| match attr. value {
23
+ let ignore = binding. field . attrs . iter ( ) . any ( |attr| match attr. value {
25
24
syn:: MetaItem :: Word ( ref ident) |
26
25
syn:: MetaItem :: List ( ref ident, _) if ident == "ignore_heap_size_of" => {
27
26
panic ! ( "#[ignore_heap_size_of] should have an explanation, \
28
27
e.g. #[ignore_heap_size_of = \" because reasons\" ]") ;
29
28
}
30
29
syn:: MetaItem :: NameValue ( ref ident, _) if ident == "ignore_heap_size_of" => {
31
- ignore = true ;
32
- false // Don’t retain
30
+ true
33
31
}
34
- _ => true // Do retain everything else
32
+ _ => false ,
35
33
} ) ;
36
34
if ignore {
37
35
None
@@ -66,8 +64,6 @@ fn expand_string(input: &str) -> String {
66
64
}
67
65
68
66
let tokens = quote ! {
69
- #type_
70
-
71
67
impl #impl_generics :: heapsize:: HeapSizeOf for #name #ty_generics #where_clause {
72
68
#[ inline]
73
69
#[ allow( unused_variables, unused_mut, unreachable_code) ]
@@ -96,7 +92,7 @@ fn test_struct() {
96
92
$e, expanded)
97
93
}
98
94
}
99
- match_count ! ( "struct Foo<T> { bar: Bar, baz: T, z: Arc<T> } " , 1 ) ;
95
+ match_count ! ( "struct" , 0 ) ;
100
96
match_count ! ( "ignore_heap_size_of" , 0 ) ;
101
97
match_count ! ( "impl<T> ::heapsize::HeapSizeOf for Foo<T> where T: ::heapsize::HeapSizeOf {" , 1 ) ;
102
98
match_count ! ( "sum += ::heapsize::HeapSizeOf::heap_size_of_children(" , 2 ) ;
0 commit comments