]> git.proxmox.com Git - rustc.git/blame - src/libsyntax/parse/classify.rs
New upstream version 1.40.0+dfsg1
[rustc.git] / src / libsyntax / parse / classify.rs
CommitLineData
1a4d82fc
JJ
1//! Routines the parser uses to classify AST nodes
2
3// Predicates on exprs and stmts that the pretty-printer and parser use
223e47cc 4
9fa01778 5use crate::ast;
223e47cc 6
1a4d82fc
JJ
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 {...}
12/// |x| 5
13/// isn't parsed as (if true {...} else {...} | x) | 5
14pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
e74abb32 15 match e.kind {
7453a54e 16 ast::ExprKind::If(..) |
7453a54e 17 ast::ExprKind::Match(..) |
94b46f34 18 ast::ExprKind::Block(..) |
7453a54e 19 ast::ExprKind::While(..) |
7453a54e 20 ast::ExprKind::Loop(..) |
3b2f2976 21 ast::ExprKind::ForLoop(..) |
b7449926 22 ast::ExprKind::TryBlock(..) => false,
7453a54e 23 _ => true,
223e47cc
LB
24 }
25}