Implement Parse for Arm
diff --git a/src/expr.rs b/src/expr.rs
index d4b689a..1c883c8 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1897,7 +1897,7 @@
let mut arms = Vec::new();
while !content.is_empty() {
- arms.push(content.call(match_arm)?);
+ arms.push(content.call(Arm::parse)?);
}
Ok(ExprMatch {
@@ -1934,52 +1934,6 @@
}
#[cfg(feature = "full")]
- fn match_arm(input: ParseStream) -> Result<Arm> {
- let requires_comma;
- Ok(Arm {
- attrs: input.call(Attribute::parse_outer)?,
- leading_vert: input.parse()?,
- pats: {
- let mut pats = Punctuated::new();
- let value: Pat = input.parse()?;
- pats.push_value(value);
- loop {
- if !input.peek(Token![|]) {
- break;
- }
- let punct = input.parse()?;
- pats.push_punct(punct);
- let value: Pat = input.parse()?;
- pats.push_value(value);
- }
- pats
- },
- guard: {
- if input.peek(Token![if]) {
- let if_token: Token![if] = input.parse()?;
- let guard: Expr = input.parse()?;
- Some((if_token, Box::new(guard)))
- } else {
- None
- }
- },
- fat_arrow_token: input.parse()?,
- body: {
- let body = input.call(expr_early)?;
- requires_comma = requires_terminator(&body);
- Box::new(body)
- },
- comma: {
- if requires_comma && !input.is_empty() {
- Some(input.parse()?)
- } else {
- input.parse()?
- }
- },
- })
- }
-
- #[cfg(feature = "full")]
fn expr_closure(input: ParseStream, allow_struct: AllowStruct) -> Result<ExprClosure> {
let asyncness: Option<Token![async]> = input.parse()?;
let movability: Option<Token![static]> = if asyncness.is_none() {
@@ -2782,6 +2736,54 @@
}
}
+ #[cfg(feature = "full")]
+ impl Parse for Arm {
+ fn parse(input: ParseStream) -> Result<Arm> {
+ let requires_comma;
+ Ok(Arm {
+ attrs: input.call(Attribute::parse_outer)?,
+ leading_vert: input.parse()?,
+ pats: {
+ let mut pats = Punctuated::new();
+ let value: Pat = input.parse()?;
+ pats.push_value(value);
+ loop {
+ if !input.peek(Token![|]) {
+ break;
+ }
+ let punct = input.parse()?;
+ pats.push_punct(punct);
+ let value: Pat = input.parse()?;
+ pats.push_value(value);
+ }
+ pats
+ },
+ guard: {
+ if input.peek(Token![if]) {
+ let if_token: Token![if] = input.parse()?;
+ let guard: Expr = input.parse()?;
+ Some((if_token, Box::new(guard)))
+ } else {
+ None
+ }
+ },
+ fat_arrow_token: input.parse()?,
+ body: {
+ let body = input.call(expr_early)?;
+ requires_comma = requires_terminator(&body);
+ Box::new(body)
+ },
+ comma: {
+ if requires_comma && !input.is_empty() {
+ Some(input.parse()?)
+ } else {
+ input.parse()?
+ }
+ },
+ })
+ }
+ }
+
impl Parse for Index {
fn parse(input: ParseStream) -> Result<Self> {
let lit: LitInt = input.parse()?;