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 ExprUnary #1008

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: 24 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,11 +1496,7 @@ pub(crate) mod parsing {
} else if input.peek(Token![box]) {
expr_box(input, attrs, allow_struct).map(Expr::Box)
} else if input.peek(Token![*]) || input.peek(Token![!]) || input.peek(Token![-]) {
Ok(Expr::Unary(ExprUnary {
attrs,
op: input.parse()?,
expr: Box::new(unary_expr(input, allow_struct)?),
}))
expr_unary(input, attrs, allow_struct).map(Expr::Unary)
} else {
trailer_expr(attrs, input, allow_struct)
}
Expand Down Expand Up @@ -2240,7 +2236,6 @@ pub(crate) mod parsing {
ExprMethodCall, MethodCall, "expected method call expression",
ExprTuple, Tuple, "expected tuple expression",
ExprBinary, Binary, "expected binary operation",
ExprUnary, Unary, "expected unary operation",
ExprCast, Cast, "expected cast expression",
ExprType, Type, "expected type ascription expression",
ExprLet, Let, "expected let guard",
Expand Down Expand Up @@ -2281,6 +2276,29 @@ pub(crate) mod parsing {
})
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprUnary {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = Vec::new();
let allow_struct = AllowStruct(true);
expr_unary(input, attrs, allow_struct)
}
}

#[cfg(feature = "full")]
fn expr_unary(
input: ParseStream,
attrs: Vec<Attribute>,
allow_struct: AllowStruct,
) -> Result<ExprUnary> {
Ok(ExprUnary {
attrs,
op: input.parse()?,
expr: Box::new(unary_expr(input, allow_struct)?),
})
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprTryBlock {
Expand Down