File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
crates/formality-macros/src Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ fn debug_variant_with_attr(
149
149
stream. extend ( match op {
150
150
spec:: FormalitySpecOp :: Field {
151
151
name,
152
- mode : FieldMode :: Single ,
152
+ mode : FieldMode :: Single | FieldMode :: Optional ,
153
153
} => {
154
154
quote_spanned ! {
155
155
name. span( ) =>
Original file line number Diff line number Diff line change @@ -157,6 +157,17 @@ fn parse_variant_with_attr(
157
157
}
158
158
}
159
159
160
+ spec:: FormalitySpecOp :: Field {
161
+ name,
162
+ mode : FieldMode :: Optional ,
163
+ } => {
164
+ quote_spanned ! {
165
+ name. span( ) =>
166
+ let ( #name, text) = parse:: CoreParse :: parse_opt( scope, text) ?;
167
+ let #name = #name. unwrap_or_default( ) ;
168
+ }
169
+ }
170
+
160
171
spec:: FormalitySpecOp :: Field {
161
172
name,
162
173
mode : FieldMode :: Many ,
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ pub enum FieldMode {
45
45
/// If the next op is a fixed character, stop parsing when we see that.
46
46
/// Otherwise parse as many we can greedily.
47
47
Comma ,
48
+
49
+ /// $?x -- parse `x` if we can, but otherwise use `Default`
50
+ Optional ,
48
51
}
49
52
50
53
impl syn:: parse:: Parse for FormalitySpec {
@@ -124,6 +127,7 @@ fn parse_variable_binding(
124
127
let mode = match punct. as_char ( ) {
125
128
',' => FieldMode :: Comma ,
126
129
'*' => FieldMode :: Many ,
130
+ '?' => FieldMode :: Optional ,
127
131
'$' => return Ok ( FormalitySpecOp :: Char { punct } ) ,
128
132
_ => return error ( ) ,
129
133
} ;
You can’t perform that action at this time.
0 commit comments