about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorMarcus Klaas <mail@marcusklaas.nl>2015-09-25 12:53:25 +0200
committerMarcus Klaas <mail@marcusklaas.nl>2015-09-25 13:01:20 +0200
commita7690cb1e5853f8206eea66018ff08fe393c533a (patch)
treed055bb3a9204f9ccb9593cea0bbdb3f63527e0da /src/expr.rs
parente80080deb60e78e7a57be4d693ca8e96cb14a1b2 (diff)
Make rewrite_string return `Option<String>`
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/expr.rs b/src/expr.rs
index a2be6ee8fd1..2e87bfbc19a 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -374,7 +374,11 @@ impl Rewrite for ast::Block {
                     // 9 = "unsafe  {".len(), 7 = "unsafe ".len()
                     let budget = try_opt!(width.checked_sub(9));
                     format!("unsafe {} ",
-                            rewrite_comment(trimmed, true, budget, offset + 7, context.config))
+                            try_opt!(rewrite_comment(trimmed,
+                                                     true,
+                                                     budget,
+                                                     offset + 7,
+                                                     context.config)))
                 } else {
                     "unsafe ".to_owned()
                 };
@@ -658,7 +662,7 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
                              width: usize,
                              arm_indent: Indent,
                              arm_indent_str: &str)
-                             -> String {
+                             -> Option<String> {
     // The leading "," is not part of the arm-comment
     let missed_str = match missed_str.find_uncommented(",") {
         Some(n) => &missed_str[n+1..],
@@ -684,11 +688,17 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
     }
     let missed_str = missed_str[first..].trim();
     if !missed_str.is_empty() {
+        let comment = try_opt!(rewrite_comment(&missed_str,
+                                               false,
+                                               width,
+                                               arm_indent,
+                                               context.config));
         result.push('\n');
         result.push_str(arm_indent_str);
-        result.push_str(&rewrite_comment(&missed_str, false, width, arm_indent, context.config));
+        result.push_str(&comment);
     }
-    return result;
+
+    Some(result)
 }
 
 fn rewrite_match(context: &RewriteContext,
@@ -722,11 +732,12 @@ fn rewrite_match(context: &RewriteContext,
         } else {
             context.snippet(mk_sp(arm_end_pos(&arms[i-1]), arm_start_pos(arm)))
         };
-        result.push_str(&rewrite_match_arm_comment(context,
-                                                   &missed_str,
-                                                   width,
-                                                   arm_indent,
-                                                   &arm_indent_str));
+        let comment = try_opt!(rewrite_match_arm_comment(context,
+                                                         &missed_str,
+                                                         width,
+                                                         arm_indent,
+                                                         &arm_indent_str));
+        result.push_str(&comment);
         result.push('\n');
         result.push_str(&arm_indent_str);
 
@@ -742,11 +753,12 @@ fn rewrite_match(context: &RewriteContext,
         }
     }
     let last_comment = context.snippet(mk_sp(arm_end_pos(&arms[arms.len() - 1]), span.hi));
-    result.push_str(&rewrite_match_arm_comment(context,
-                                               &last_comment,
-                                               width,
-                                               arm_indent,
-                                               &arm_indent_str));
+    let comment = try_opt!(rewrite_match_arm_comment(context,
+                                                     &last_comment,
+                                                     width,
+                                                     arm_indent,
+                                                     &arm_indent_str));
+    result.push_str(&comment);
     result.push('\n');
     result.push_str(&(context.block_indent + context.overflow_indent).to_string(context.config));
     result.push('}');
@@ -1004,7 +1016,7 @@ fn rewrite_string_lit(context: &RewriteContext,
     let string_lit = context.snippet(span);
     let str_lit = &string_lit[1..string_lit.len() - 1]; // Remove the quote characters.
 
-    Some(rewrite_string(str_lit, &fmt))
+    rewrite_string(str_lit, &fmt)
 }
 
 pub fn rewrite_call<R>(context: &RewriteContext,