From 242de88a5e10b9d980c18f9665f56c96cbfd63aa Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 1 Apr 2021 13:22:13 -0400 Subject: [PATCH] impl Parse for ExprUnary --- src/expr.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index e71a2d59be..a5cc974b6d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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) } @@ -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", @@ -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 { + 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, + allow_struct: AllowStruct, + ) -> Result { + 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 {