diff options
| author | Kevin Yeh <kevinyeah@utexas.edu> | 2015-11-19 01:53:25 -0600 |
|---|---|---|
| committer | Kevin Yeh <kevinyeah@utexas.edu> | 2015-11-19 14:23:56 -0600 |
| commit | 22837b07483c91f8fbda2bd1df3e2bb83af5c48d (patch) | |
| tree | 4828fa58b7ecede1fb27b9e08adb483e9bcff26a /src/expr.rs | |
| parent | 4d7de5a16e230d8cf533c1cafee574862f06b968 (diff) | |
Combine block utilities
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/expr.rs b/src/expr.rs index c4b01e38b42..7616ef0c328 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -688,6 +688,27 @@ fn is_simple_block(block: &ast::Block, codemap: &CodeMap) -> bool { !contains_comment(&snippet) } +/// Checks whether a block contains at most one statement or expression, and no comments. +pub fn is_simple_block_stmt(block: &ast::Block, codemap: &CodeMap) -> bool { + if (!block.stmts.is_empty() && block.expr.is_some()) || + (block.stmts.len() != 1 && block.expr.is_none()) { + return false; + } + + let snippet = codemap.span_to_snippet(block.span).unwrap(); + !contains_comment(&snippet) +} + +/// Checks whether a block contains no statements, expressions, or comments. +pub fn is_empty_block(block: &ast::Block, codemap: &CodeMap) -> bool { + if !block.stmts.is_empty() || block.expr.is_some() { + return false; + } + + let snippet = codemap.span_to_snippet(block.span).unwrap(); + !contains_comment(&snippet) +} + // inter-match-arm-comment-rules: // - all comments following a match arm before the start of the next arm // are about the second arm |
