Skip to content

Commit

Permalink
Merge pull request #1015 from dtolnay/exprparse
Browse files Browse the repository at this point in the history
impl Parse for ExprYield
  • Loading branch information
dtolnay committed Apr 1, 2021
2 parents cd3b353 + 7687dac commit 203eef8
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/expr.rs
Expand Up @@ -1738,7 +1738,7 @@ pub(crate) mod parsing {
} else if input.peek(Token![match]) {
input.parse().map(Expr::Match)
} else if input.peek(Token![yield]) {
input.call(expr_yield).map(Expr::Yield)
input.parse().map(Expr::Yield)
} else if input.peek(Token![unsafe]) {
input.parse().map(Expr::Unsafe)
} else if input.peek(Token![const]) {
Expand Down Expand Up @@ -2247,7 +2247,6 @@ pub(crate) mod parsing {
ExprIndex, Index, "expected indexing expression",
ExprRange, Range, "expected range expression",
ExprTry, Try, "expected try expression",
ExprYield, Yield, "expected yield expression",
}

#[cfg(feature = "full")]
Expand Down Expand Up @@ -2351,18 +2350,21 @@ pub(crate) mod parsing {
}

#[cfg(feature = "full")]
fn expr_yield(input: ParseStream) -> Result<ExprYield> {
Ok(ExprYield {
attrs: Vec::new(),
yield_token: input.parse()?,
expr: {
if !input.is_empty() && !input.peek(Token![,]) && !input.peek(Token![;]) {
Some(input.parse()?)
} else {
None
}
},
})
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprYield {
fn parse(input: ParseStream) -> Result<Self> {
Ok(ExprYield {
attrs: Vec::new(),
yield_token: input.parse()?,
expr: {
if !input.is_empty() && !input.peek(Token![,]) && !input.peek(Token![;]) {
Some(input.parse()?)
} else {
None
}
},
})
}
}

#[cfg(feature = "full")]
Expand Down

0 comments on commit 203eef8

Please sign in to comment.