1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::ast::{self, BlockCheckMode};
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
match e.node {
ast::ExprKind::If(..)
| ast::ExprKind::IfLet(..)
| ast::ExprKind::Match(..)
| ast::ExprKind::Block(_)
| ast::ExprKind::While(..)
| ast::ExprKind::WhileLet(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..) => false,
_ => true,
}
}
pub fn expr_is_simple_block(e: &ast::Expr) -> bool {
match e.node {
ast::ExprKind::Block(ref block) => block.rules == BlockCheckMode::Default,
_ => false,
}
}
pub fn stmt_ends_with_semi(stmt: &ast::StmtKind) -> bool {
match *stmt {
ast::StmtKind::Local(_) => true,
ast::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(e),
ast::StmtKind::Item(_) | ast::StmtKind::Semi(..) | ast::StmtKind::Mac(..) => false,
}
}