Skip to content

Commit 65a77e1

Browse files
fail better for enum variant fields
1 parent 624e338 commit 65a77e1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

derive/src/from_pest/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,21 @@ fn derive_for_enum(
187187
let span = pair.as_span();
188188
let mut inner = pair.clone().into_inner();
189189
let inner = &mut inner;
190-
let this = #construct_variant;
191-
if inner.clone().next().is_some() {
192-
#extraneous
193-
Err(::from_pest::ConversionError::Extraneous {
194-
current_node: stringify!(#variant_name),
195-
})?;
190+
let mut clone = inner.clone();
191+
let pair = clone.next().ok_or(::from_pest::ConversionError::NoMatch)?;
192+
if pair.as_rule() == #rule_enum::#variant_name {
193+
let this = #construct_variant;
194+
if inner.clone().next().is_some() {
195+
#extraneous
196+
Err(::from_pest::ConversionError::Extraneous {
197+
current_node: stringify!(#variant_name),
198+
})?;
199+
}
200+
Ok(this)
201+
} else {
202+
Err(e)
196203
}
197-
Ok(this)
198-
})
204+
})
199205
})
200206
.collect::<Result<_>>()?;
201207

@@ -204,7 +210,7 @@ fn derive_for_enum(
204210
let pair = clone.next().ok_or(::from_pest::ConversionError::NoMatch)?;
205211
if pair.as_rule() == #rule_enum::#rule_variant {
206212
let this = Err(::from_pest::ConversionError::NoMatch)
207-
#(.or_else(|_: ::from_pest::ConversionError<::from_pest::Void>| {
213+
#(.or_else(|e: ::from_pest::ConversionError<::from_pest::Void>| {
208214
#convert_variants
209215
}))*?;
210216
*pest = clone;

0 commit comments

Comments
 (0)