|
1 | | -// ignore-tidy-linelength |
2 | | - |
3 | 1 | macro_rules! enum_from_u32 { |
4 | 2 | ($(#[$attr:meta])* pub enum $name:ident { |
5 | 3 | $($variant:ident = $e:expr,)* |
@@ -52,120 +50,6 @@ macro_rules! span_bug { |
52 | 50 | }) |
53 | 51 | } |
54 | 52 |
|
55 | | -#[macro_export] |
56 | | -macro_rules! __impl_stable_hash_field { |
57 | | - ($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher)); |
58 | | - ($field:ident, $ctx:expr, $hasher:expr, _) => ({ let _ = $field; }); |
59 | | - ($field:ident, $ctx:expr, $hasher:expr, $delegate:expr) => ($delegate.hash_stable($ctx, $hasher)); |
60 | | -} |
61 | | - |
62 | | -#[macro_export] |
63 | | -macro_rules! impl_stable_hash_for { |
64 | | - // Enums |
65 | | - (enum $enum_name:path { |
66 | | - $( $variant:ident |
67 | | - // this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`, |
68 | | - // when it should be only one or the other |
69 | | - $( ( $($field:ident $(-> $delegate:tt)?),* ) )? |
70 | | - $( { $($named_field:ident $(-> $named_delegate:tt)?),* } )? |
71 | | - ),* $(,)? |
72 | | - }) => { |
73 | | - impl_stable_hash_for!( |
74 | | - impl<> for enum $enum_name [ $enum_name ] { $( $variant |
75 | | - $( ( $($field $(-> $delegate)?),* ) )? |
76 | | - $( { $($named_field $(-> $named_delegate)?),* } )? |
77 | | - ),* } |
78 | | - ); |
79 | | - }; |
80 | | - // We want to use the enum name both in the `impl ... for $enum_name` as well as for |
81 | | - // importing all the variants. Unfortunately it seems we have to take the name |
82 | | - // twice for this purpose |
83 | | - (impl<$($T:ident),* $(,)?> |
84 | | - for enum $enum_name:path |
85 | | - [ $enum_path:path ] |
86 | | - { |
87 | | - $( $variant:ident |
88 | | - // this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`, |
89 | | - // when it should be only one or the other |
90 | | - $( ( $($field:ident $(-> $delegate:tt)?),* ) )? |
91 | | - $( { $($named_field:ident $(-> $named_delegate:tt)?),* } )? |
92 | | - ),* $(,)? |
93 | | - }) => { |
94 | | - impl<$($T,)*> |
95 | | - ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> |
96 | | - for $enum_name |
97 | | - where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* |
98 | | - { |
99 | | - #[inline] |
100 | | - fn hash_stable(&self, |
101 | | - __ctx: &mut $crate::ich::StableHashingContext<'a>, |
102 | | - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { |
103 | | - use $enum_path::*; |
104 | | - ::std::mem::discriminant(self).hash_stable(__ctx, __hasher); |
105 | | - |
106 | | - match *self { |
107 | | - $( |
108 | | - $variant $( ( $(ref $field),* ) )? $( { $(ref $named_field),* } )? => { |
109 | | - $($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*)? |
110 | | - $($( __impl_stable_hash_field!($named_field, __ctx, __hasher $(, $named_delegate)?) );*)? |
111 | | - } |
112 | | - )* |
113 | | - } |
114 | | - } |
115 | | - } |
116 | | - }; |
117 | | - // Structs |
118 | | - (struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => { |
119 | | - impl_stable_hash_for!( |
120 | | - impl<> for struct $struct_name { $($field $(-> $delegate)?),* } |
121 | | - ); |
122 | | - }; |
123 | | - (impl<$($T:ident),* $(,)?> for struct $struct_name:path { |
124 | | - $($field:ident $(-> $delegate:tt)?),* $(,)? |
125 | | - }) => { |
126 | | - impl<$($T,)*> |
127 | | - ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name |
128 | | - where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* |
129 | | - { |
130 | | - #[inline] |
131 | | - fn hash_stable(&self, |
132 | | - __ctx: &mut $crate::ich::StableHashingContext<'a>, |
133 | | - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { |
134 | | - let $struct_name { |
135 | | - $(ref $field),* |
136 | | - } = *self; |
137 | | - |
138 | | - $( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );* |
139 | | - } |
140 | | - } |
141 | | - }; |
142 | | - // Tuple structs |
143 | | - // We cannot use normal parentheses here, the parser won't allow it |
144 | | - (tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => { |
145 | | - impl_stable_hash_for!( |
146 | | - impl<> for tuple_struct $struct_name { $($field $(-> $delegate)?),* } |
147 | | - ); |
148 | | - }; |
149 | | - (impl<$($T:ident),* $(,)?> |
150 | | - for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => { |
151 | | - impl<$($T,)*> |
152 | | - ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name |
153 | | - where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* |
154 | | - { |
155 | | - #[inline] |
156 | | - fn hash_stable(&self, |
157 | | - __ctx: &mut $crate::ich::StableHashingContext<'a>, |
158 | | - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { |
159 | | - let $struct_name ( |
160 | | - $(ref $field),* |
161 | | - ) = *self; |
162 | | - |
163 | | - $( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );* |
164 | | - } |
165 | | - } |
166 | | - }; |
167 | | -} |
168 | | - |
169 | 53 | /////////////////////////////////////////////////////////////////////////// |
170 | 54 | // Lift and TypeFoldable macros |
171 | 55 | // |
|
0 commit comments