Skip to content

Commit

Permalink
Merge pull request #1796 from dtolnay/vecarm
Browse files Browse the repository at this point in the history
Allow Vec<Arm> in parse_quote
  • Loading branch information
dtolnay authored Dec 22, 2024
2 parents 384516b + d2bc3a3 commit 1c739cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,10 +2328,7 @@ pub(crate) mod parsing {
let brace_token = braced!(content in input);
attr::parsing::parse_inner(&content, &mut attrs)?;

let mut arms = Vec::new();
while !content.is_empty() {
arms.push(content.call(Arm::parse)?);
}
let arms = Arm::parse_multiple(&content)?;

Ok(ExprMatch {
attrs,
Expand Down Expand Up @@ -2945,6 +2942,17 @@ pub(crate) mod parsing {
}
}

#[cfg(feature = "full")]
impl Arm {
pub(crate) fn parse_multiple(input: ParseStream) -> Result<Vec<Self>> {
let mut arms = Vec::new();
while !input.is_empty() {
arms.push(input.call(Arm::parse)?);
}
Ok(arms)
}
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for Arm {
Expand Down
9 changes: 8 additions & 1 deletion src/parse_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ use crate::punctuated::Punctuated;
#[cfg(any(feature = "full", feature = "derive"))]
use crate::{attr, Attribute, Field, FieldMutability, Ident, Type, Visibility};
#[cfg(feature = "full")]
use crate::{Block, Pat, Stmt};
use crate::{Arm, Block, Pat, Stmt};

#[cfg(any(feature = "full", feature = "derive"))]
impl ParseQuote for Attribute {
Expand Down Expand Up @@ -220,3 +220,10 @@ impl ParseQuote for Vec<Stmt> {
Block::parse_within(input)
}
}

#[cfg(feature = "full")]
impl ParseQuote for Vec<Arm> {
fn parse(input: ParseStream) -> Result<Self> {
Arm::parse_multiple(input)
}
}

0 comments on commit 1c739cb

Please sign in to comment.