@@ -38,33 +38,16 @@ fn parse_attributes(field: &syn::Field) -> Attributes {
38
38
attrs
39
39
}
40
40
41
- pub fn hash_stable_generic_derive ( mut s : synstructure:: Structure < ' _ > ) -> proc_macro2:: TokenStream {
41
+ pub ( crate ) fn hash_stable_generic_derive (
42
+ mut s : synstructure:: Structure < ' _ > ,
43
+ ) -> proc_macro2:: TokenStream {
42
44
let generic: syn:: GenericParam = parse_quote ! ( __CTX) ;
43
45
s. add_bounds ( synstructure:: AddBounds :: Generics ) ;
44
46
s. add_impl_generic ( generic) ;
45
47
s. add_where_predicate ( parse_quote ! { __CTX: crate :: HashStableContext } ) ;
46
- let body = s. each ( |bi| {
47
- let attrs = parse_attributes ( bi. ast ( ) ) ;
48
- if attrs. ignore {
49
- quote ! { }
50
- } else if let Some ( project) = attrs. project {
51
- quote ! {
52
- ( & #bi. #project) . hash_stable( __hcx, __hasher) ;
53
- }
54
- } else {
55
- quote ! {
56
- #bi. hash_stable( __hcx, __hasher) ;
57
- }
58
- }
59
- } ) ;
60
48
61
- let discriminant = match s. ast ( ) . data {
62
- syn:: Data :: Enum ( _) => quote ! {
63
- :: std:: mem:: discriminant( self ) . hash_stable( __hcx, __hasher) ;
64
- } ,
65
- syn:: Data :: Struct ( _) => quote ! { } ,
66
- syn:: Data :: Union ( _) => panic ! ( "cannot derive on union" ) ,
67
- } ;
49
+ let discriminant = hash_stable_discriminant ( & mut s) ;
50
+ let body = hash_stable_body ( & mut s) ;
68
51
69
52
s. bound_impl (
70
53
quote ! ( :: rustc_data_structures:: stable_hasher:: HashStable <__CTX>) ,
@@ -81,32 +64,13 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
81
64
)
82
65
}
83
66
84
- pub fn hash_stable_derive ( mut s : synstructure:: Structure < ' _ > ) -> proc_macro2:: TokenStream {
67
+ pub ( crate ) fn hash_stable_derive ( mut s : synstructure:: Structure < ' _ > ) -> proc_macro2:: TokenStream {
85
68
let generic: syn:: GenericParam = parse_quote ! ( ' __ctx) ;
86
69
s. add_bounds ( synstructure:: AddBounds :: Generics ) ;
87
70
s. add_impl_generic ( generic) ;
88
- let body = s. each ( |bi| {
89
- let attrs = parse_attributes ( bi. ast ( ) ) ;
90
- if attrs. ignore {
91
- quote ! { }
92
- } else if let Some ( project) = attrs. project {
93
- quote ! {
94
- ( & #bi. #project) . hash_stable( __hcx, __hasher) ;
95
- }
96
- } else {
97
- quote ! {
98
- #bi. hash_stable( __hcx, __hasher) ;
99
- }
100
- }
101
- } ) ;
102
71
103
- let discriminant = match s. ast ( ) . data {
104
- syn:: Data :: Enum ( _) => quote ! {
105
- :: std:: mem:: discriminant( self ) . hash_stable( __hcx, __hasher) ;
106
- } ,
107
- syn:: Data :: Struct ( _) => quote ! { } ,
108
- syn:: Data :: Union ( _) => panic ! ( "cannot derive on union" ) ,
109
- } ;
72
+ let discriminant = hash_stable_discriminant ( & mut s) ;
73
+ let body = hash_stable_body ( & mut s) ;
110
74
111
75
s. bound_impl (
112
76
quote ! (
@@ -126,3 +90,30 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To
126
90
} ,
127
91
)
128
92
}
93
+
94
+ fn hash_stable_discriminant ( s : & mut synstructure:: Structure < ' _ > ) -> proc_macro2:: TokenStream {
95
+ match s. ast ( ) . data {
96
+ syn:: Data :: Enum ( _) => quote ! {
97
+ :: std:: mem:: discriminant( self ) . hash_stable( __hcx, __hasher) ;
98
+ } ,
99
+ syn:: Data :: Struct ( _) => quote ! { } ,
100
+ syn:: Data :: Union ( _) => panic ! ( "cannot derive on union" ) ,
101
+ }
102
+ }
103
+
104
+ fn hash_stable_body ( s : & mut synstructure:: Structure < ' _ > ) -> proc_macro2:: TokenStream {
105
+ s. each ( |bi| {
106
+ let attrs = parse_attributes ( bi. ast ( ) ) ;
107
+ if attrs. ignore {
108
+ quote ! { }
109
+ } else if let Some ( project) = attrs. project {
110
+ quote ! {
111
+ ( & #bi. #project) . hash_stable( __hcx, __hasher) ;
112
+ }
113
+ } else {
114
+ quote ! {
115
+ #bi. hash_stable( __hcx, __hasher) ;
116
+ }
117
+ }
118
+ } )
119
+ }
0 commit comments