@@ -45,28 +45,9 @@ pub(crate) fn hash_stable_generic_derive(
45
45
s. add_bounds ( synstructure:: AddBounds :: Generics ) ;
46
46
s. add_impl_generic ( generic) ;
47
47
s. add_where_predicate ( parse_quote ! { __CTX: crate :: HashStableContext } ) ;
48
- let body = s. each ( |bi| {
49
- let attrs = parse_attributes ( bi. ast ( ) ) ;
50
- if attrs. ignore {
51
- quote ! { }
52
- } else if let Some ( project) = attrs. project {
53
- quote ! {
54
- ( & #bi. #project) . hash_stable( __hcx, __hasher) ;
55
- }
56
- } else {
57
- quote ! {
58
- #bi. hash_stable( __hcx, __hasher) ;
59
- }
60
- }
61
- } ) ;
62
48
63
- let discriminant = match s. ast ( ) . data {
64
- syn:: Data :: Enum ( _) => quote ! {
65
- :: std:: mem:: discriminant( self ) . hash_stable( __hcx, __hasher) ;
66
- } ,
67
- syn:: Data :: Struct ( _) => quote ! { } ,
68
- syn:: Data :: Union ( _) => panic ! ( "cannot derive on union" ) ,
69
- } ;
49
+ let discriminant = hash_stable_discriminant ( & mut s) ;
50
+ let body = hash_stable_body ( & mut s) ;
70
51
71
52
s. bound_impl (
72
53
quote ! ( :: rustc_data_structures:: stable_hasher:: HashStable <__CTX>) ,
@@ -87,28 +68,9 @@ pub(crate) fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_mac
87
68
let generic: syn:: GenericParam = parse_quote ! ( ' __ctx) ;
88
69
s. add_bounds ( synstructure:: AddBounds :: Generics ) ;
89
70
s. add_impl_generic ( generic) ;
90
- let body = s. each ( |bi| {
91
- let attrs = parse_attributes ( bi. ast ( ) ) ;
92
- if attrs. ignore {
93
- quote ! { }
94
- } else if let Some ( project) = attrs. project {
95
- quote ! {
96
- ( & #bi. #project) . hash_stable( __hcx, __hasher) ;
97
- }
98
- } else {
99
- quote ! {
100
- #bi. hash_stable( __hcx, __hasher) ;
101
- }
102
- }
103
- } ) ;
104
71
105
- let discriminant = match s. ast ( ) . data {
106
- syn:: Data :: Enum ( _) => quote ! {
107
- :: std:: mem:: discriminant( self ) . hash_stable( __hcx, __hasher) ;
108
- } ,
109
- syn:: Data :: Struct ( _) => quote ! { } ,
110
- syn:: Data :: Union ( _) => panic ! ( "cannot derive on union" ) ,
111
- } ;
72
+ let discriminant = hash_stable_discriminant ( & mut s) ;
73
+ let body = hash_stable_body ( & mut s) ;
112
74
113
75
s. bound_impl (
114
76
quote ! (
@@ -128,3 +90,30 @@ pub(crate) fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_mac
128
90
} ,
129
91
)
130
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