Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Parse for ExprYield #1015

Merged
merged 1 commit into from Apr 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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