Skip to content

Commit 1c739cb

Browse files
authored
Merge pull request #1796 from dtolnay/vecarm
Allow Vec<Arm> in parse_quote
2 parents 384516b + d2bc3a3 commit 1c739cb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/expr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -2328,10 +2328,7 @@ pub(crate) mod parsing {
23282328
let brace_token = braced!(content in input);
23292329
attr::parsing::parse_inner(&content, &mut attrs)?;
23302330

2331-
let mut arms = Vec::new();
2332-
while !content.is_empty() {
2333-
arms.push(content.call(Arm::parse)?);
2334-
}
2331+
let arms = Arm::parse_multiple(&content)?;
23352332

23362333
Ok(ExprMatch {
23372334
attrs,
@@ -2945,6 +2942,17 @@ pub(crate) mod parsing {
29452942
}
29462943
}
29472944

2945+
#[cfg(feature = "full")]
2946+
impl Arm {
2947+
pub(crate) fn parse_multiple(input: ParseStream) -> Result<Vec<Self>> {
2948+
let mut arms = Vec::new();
2949+
while !input.is_empty() {
2950+
arms.push(input.call(Arm::parse)?);
2951+
}
2952+
Ok(arms)
2953+
}
2954+
}
2955+
29482956
#[cfg(feature = "full")]
29492957
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
29502958
impl Parse for Arm {

src/parse_quote.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ use crate::punctuated::Punctuated;
140140
#[cfg(any(feature = "full", feature = "derive"))]
141141
use crate::{attr, Attribute, Field, FieldMutability, Ident, Type, Visibility};
142142
#[cfg(feature = "full")]
143-
use crate::{Block, Pat, Stmt};
143+
use crate::{Arm, Block, Pat, Stmt};
144144

145145
#[cfg(any(feature = "full", feature = "derive"))]
146146
impl ParseQuote for Attribute {
@@ -220,3 +220,10 @@ impl ParseQuote for Vec<Stmt> {
220220
Block::parse_within(input)
221221
}
222222
}
223+
224+
#[cfg(feature = "full")]
225+
impl ParseQuote for Vec<Arm> {
226+
fn parse(input: ParseStream) -> Result<Self> {
227+
Arm::parse_multiple(input)
228+
}
229+
}

0 commit comments

Comments
 (0)