Skip to content

Commit

Permalink
impl Parse for ExprUnary
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 1, 2021
1 parent 52607fb commit 242de88
Showing 1 changed file with 24 additions and 6 deletions.
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

0 comments on commit 242de88

Please sign in to comment.