]> git.lizzy.rs Git - rust.git/commitdiff
Combine block utilities
authorKevin Yeh <kevinyeah@utexas.edu>
Thu, 19 Nov 2015 07:53:25 +0000 (01:53 -0600)
committerKevin Yeh <kevinyeah@utexas.edu>
Thu, 19 Nov 2015 20:23:56 +0000 (14:23 -0600)
src/expr.rs
src/items.rs

index c4b01e38b42dec2bcf2192b4137cbde610c15538..7616ef0c328ea62fad01f76f20ed2c3893c49a03 100644 (file)
@@ -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
index 58ddea0c483493d7f6eb79db3aa7372bdc9bb02e..f16f5b50e6d7fd6738ee613e173c25e848ef3d43 100644 (file)
             wrap_str, last_line_width, semicolon_for_expr, semicolon_for_stmt};
 use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic,
             DefinitiveListTactic, definitive_tactic, format_item_list};
-use expr::rewrite_assign_rhs;
-use comment::{FindUncommented, contains_comment};
+use expr::{is_empty_block, is_simple_block_stmt, rewrite_assign_rhs};
+use comment::FindUncommented;
 use visitor::FmtVisitor;
 use rewrite::{Rewrite, RewriteContext};
 use config::{Config, BlockIndentStyle, Density, ReturnIndent, BraceStyle, StructLitStyle};
 
 use syntax::{ast, abi};
-use syntax::codemap::{Span, BytePos, CodeMap, mk_sp};
+use syntax::codemap::{Span, BytePos, mk_sp};
 use syntax::print::pprust;
 use syntax::parse::token;
 
@@ -1392,23 +1392,3 @@ fn span_for_where_pred(pred: &ast::WherePredicate) -> Span {
         ast::WherePredicate::EqPredicate(ref p) => p.span,
     }
 }
-
-// Checks whether a block contains at most one statement or expression, and no comments.
-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)
-}
-
-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)
-}