1 //! Routines the parser uses to classify AST nodes
3 // Predicates on exprs and stmts that the pretty-printer and parser use
7 /// Does this expression require a semicolon to be treated
8 /// as a statement? The negation of this: 'can this expression
9 /// be used as a statement without a semicolon' -- is used
10 /// as an early-bail-out in the parser so that, for instance,
11 /// if true {...} else {...}
13 /// isn't parsed as (if true {...} else {...} | x) | 5
14 pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
18 | ast::ExprKind::Match(..)
19 | ast::ExprKind::Block(..)
20 | ast::ExprKind::While(..)
21 | ast::ExprKind::Loop(..)
22 | ast::ExprKind::ForLoop(..)
23 | ast::ExprKind::TryBlock(..)
24 | ast::ExprKind::ConstBlock(..)
28 /// If an expression ends with `}`, returns the innermost expression ending in the `}`
29 pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
41 | Range(_, Some(e), _)
50 Async(..) | Block(..) | ForLoop(..) | If(..) | Loop(..) | Match(..) | Struct(..)
51 | TryBlock(..) | While(..) => break Some(expr),