about summary refs log tree commit diff
path: root/src/items.rs
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-06-04 18:35:17 +0900
committertopecongiro <seuchida@gmail.com>2017-06-04 18:44:08 +0900
commitd54634bd7cde07b276e431fc167119e13a8aef81 (patch)
treeb0ab47bc95c3a0316534dcd2f69fc7506e986a7a /src/items.rs
parent6f1cb950d6fc91cf2938fc4aea300ed12d49b735 (diff)
Use recover_comment_removed in rewrite_static
Diffstat (limited to 'src/items.rs')
-rw-r--r--src/items.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/items.rs b/src/items.rs
index 91221e1ccc6..10359f53bdd 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -18,7 +18,7 @@ use utils::{format_mutability, format_visibility, contains_skip, end_typaram, wr
 use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, list_helper,
             DefinitiveListTactic, ListTactic, definitive_tactic, format_item_list};
 use expr::{is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, type_annotation_separator};
-use comment::{FindUncommented, contains_comment, rewrite_comment};
+use comment::{FindUncommented, contains_comment, rewrite_comment, recover_comment_removed};
 use visitor::FmtVisitor;
 use rewrite::{Rewrite, RewriteContext};
 use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style, TypeDensity};
@@ -1299,6 +1299,7 @@ pub fn rewrite_static(prefix: &str,
                       mutability: ast::Mutability,
                       expr_opt: Option<&ptr::P<ast::Expr>>,
                       offset: Indent,
+                      span: Span,
                       context: &RewriteContext)
                       -> Option<String> {
     let type_annotation_spacing = type_annotation_spacing(context.config);
@@ -1325,7 +1326,17 @@ pub fn rewrite_static(prefix: &str,
                            lhs,
                            expr,
                            Shape::legacy(remaining_width, offset.block_only()))
-            .map(|s| s + ";")
+            .and_then(|res| {
+                recover_comment_removed(res,
+                                        span,
+                                        context,
+                                        Shape {
+                                            width: context.config.max_width(),
+                                            indent: offset,
+                                            offset: offset.alignment,
+                                        })
+            })
+            .map(|s| if s.ends_with(';') { s } else { s + ";" })
     } else {
         let lhs = format!("{}{};", prefix, ty_str);
         Some(lhs)