From 22837b07483c91f8fbda2bd1df3e2bb83af5c48d Mon Sep 17 00:00:00 2001 From: Kevin Yeh Date: Thu, 19 Nov 2015 01:53:25 -0600 Subject: Combine block utilities --- src/expr.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/expr.rs') 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 -- cgit 1.4.1-3-g733a5