@@ -4,7 +4,7 @@ mod field;
44mod fields;
55
66use proc_macro2:: Span ;
7- use syn:: { FieldsNamed , Ident , Pat , PatPath , Path , Result , Variant } ;
7+ use syn:: { Expr , FieldsNamed , Ident , Pat , PatPath , Path , Result , Variant } ;
88
99pub use self :: {
1010 field:: { Field , Member } ,
@@ -27,6 +27,8 @@ pub struct Data<'a> {
2727 pub path : Path ,
2828 /// [Type](DataType) of this struct, union or variant.
2929 pub type_ : DataType < ' a > ,
30+ /// Discriminant of this variant.
31+ pub discriminant : Option < & ' a Expr > ,
3032}
3133
3234/// Type of this data.
@@ -98,6 +100,7 @@ impl<'a> Data<'a> {
98100 ident,
99101 path,
100102 type_ : DataType :: Struct ( fields) ,
103+ discriminant : None ,
101104 } )
102105 }
103106 }
@@ -114,6 +117,7 @@ impl<'a> Data<'a> {
114117 ident,
115118 path,
116119 type_ : DataType :: Tuple ( fields) ,
120+ discriminant : None ,
117121 } )
118122 }
119123 }
@@ -127,6 +131,7 @@ impl<'a> Data<'a> {
127131 qself : None ,
128132 path,
129133 } ) ) ,
134+ discriminant : None ,
130135 } ) ,
131136 syn:: Fields :: Unit => Err ( Error :: item_empty ( span) ) ,
132137 }
@@ -153,6 +158,7 @@ impl<'a> Data<'a> {
153158 ident,
154159 path,
155160 type_ : DataType :: Union ( fields) ,
161+ discriminant : None ,
156162 } )
157163 }
158164 }
@@ -185,6 +191,7 @@ impl<'a> Data<'a> {
185191 default,
186192 type_ : VariantType :: Struct ( fields) ,
187193 } ,
194+ discriminant : variant. discriminant . as_ref ( ) . map ( |( _, expr) | expr) ,
188195 } )
189196 }
190197 syn:: Fields :: Unnamed ( fields) => {
@@ -200,6 +207,7 @@ impl<'a> Data<'a> {
200207 default,
201208 type_ : VariantType :: Tuple ( fields) ,
202209 } ,
210+ discriminant : variant. discriminant . as_ref ( ) . map ( |( _, expr) | expr) ,
203211 } )
204212 }
205213 syn:: Fields :: Unit => {
@@ -218,6 +226,7 @@ impl<'a> Data<'a> {
218226 default,
219227 type_ : VariantType :: Unit ( pattern) ,
220228 } ,
229+ discriminant : variant. discriminant . as_ref ( ) . map ( |( _, expr) | expr) ,
221230 } )
222231 }
223232 }
@@ -254,15 +263,6 @@ impl<'a> Data<'a> {
254263 }
255264 }
256265
257- /// Returns the destructuring `other` pattern of this [`Data`].
258- #[ cfg( not( feature = "nightly" ) ) ]
259- pub fn other_pattern_skip ( & self ) -> & Pat {
260- match self . fields ( ) {
261- Either :: Left ( fields) => & fields. other_pattern_skip ,
262- Either :: Right ( pattern) => pattern,
263- }
264- }
265-
266266 /// Returns `true` if this variant is marked as the [`struct@Default`]. If
267267 /// not a variant, always returns `true`.
268268 pub fn is_default ( & self ) -> bool {
0 commit comments