From d2bc3a3ec3c4a2193cd2a0995bd821b2e8729291 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 21 Dec 2024 17:35:01 -0800 Subject: [PATCH] Allow Vec in parse_quote --- src/expr.rs | 16 ++++++++++++---- src/parse_quote.rs | 9 ++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 545b43dfd7..4939078a49 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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, @@ -2945,6 +2942,17 @@ pub(crate) mod parsing { } } + #[cfg(feature = "full")] + impl Arm { + pub(crate) fn parse_multiple(input: ParseStream) -> Result> { + 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 { diff --git a/src/parse_quote.rs b/src/parse_quote.rs index fa7ea79f47..6d635b445a 100644 --- a/src/parse_quote.rs +++ b/src/parse_quote.rs @@ -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 { @@ -220,3 +220,10 @@ impl ParseQuote for Vec { Block::parse_within(input) } } + +#[cfg(feature = "full")] +impl ParseQuote for Vec { + fn parse(input: ParseStream) -> Result { + Arm::parse_multiple(input) + } +}