]> git.lizzy.rs Git - rust.git/commitdiff
Format source codes
authortopecongiro <seuchida@gmail.com>
Sat, 3 Jun 2017 13:50:44 +0000 (22:50 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 4 Jun 2017 10:35:29 +0000 (19:35 +0900)
src/filemap.rs
src/items.rs
src/lib.rs
src/macros.rs
src/missed_spans.rs
src/types.rs

index d1486e94e39b77cb15daa7fd8d4f12c5f19482be..aa3ae8537af76e5b0e6c17c43bcb7ae6d68335f0 100644 (file)
@@ -143,8 +143,9 @@ fn create_diff(filename: &str,
             if let Ok((ori, fmt)) = source_and_formatted_text(text, filename, config) {
                 let mismatch = make_diff(&ori, &fmt, 3);
                 let has_diff = !mismatch.is_empty();
-                print_diff(mismatch,
-                           |line_num| format!("Diff in {} at line {}:", filename, line_num));
+                print_diff(mismatch, |line_num| {
+                    format!("Diff in {} at line {}:", filename, line_num)
+                });
                 return Ok(has_diff);
             }
         }
index 91221e1ccc691a2365d7428e6182d4bbef2316de..3406b331c4d8cda3d3f7bc81e595e18733bf5e3e 100644 (file)
@@ -1162,20 +1162,20 @@ pub fn rewrite_type_alias(context: &RewriteContext,
     let type_indent = indent + line_width;
     // Try to fit the type on the same line
     let ty_str = try_opt!(ty.rewrite(context, Shape::legacy(budget, type_indent))
-                              .or_else(|| {
-        // The line was too short, try to put the type on the next line
+        .or_else(|| {
+            // The line was too short, try to put the type on the next line
 
-        // Remove the space after '='
-        result.pop();
-        let type_indent = indent.block_indent(context.config);
-        result.push('\n');
-        result.push_str(&type_indent.to_string(context.config));
-        let budget = try_opt!(context
-                                  .config
-                                  .max_width()
-                                  .checked_sub(type_indent.width() + ";".len()));
-        ty.rewrite(context, Shape::legacy(budget, type_indent))
-    }));
+            // Remove the space after '='
+            result.pop();
+            let type_indent = indent.block_indent(context.config);
+            result.push('\n');
+            result.push_str(&type_indent.to_string(context.config));
+            let budget = try_opt!(context
+                                      .config
+                                      .max_width()
+                                      .checked_sub(type_indent.width() + ";".len()));
+            ty.rewrite(context, Shape::legacy(budget, type_indent))
+        }));
     result.push_str(&ty_str);
     result.push_str(";");
     Some(result)
index e89235631fb33afbae94b35b35b22613f9b23e9f..1635553eccd9ad590d3eb956e26e9dca607a94b1 100644 (file)
@@ -626,7 +626,7 @@ pub fn format_input<T: Write>(input: Input,
                 return filemap::write_file(file, file_name, out, config);
             }
             Ok(false)
-        }
+        },
     ) {
         Ok((file_map, has_diff)) => {
             if report.has_warnings() {
index 1193e4819eb857e449a730e93a030fb91dadc8d4..f99e236ac88e4c1a70e867310032ffbcb3f01956 100644 (file)
@@ -172,12 +172,12 @@ pub fn rewrite_macro(mac: &ast::Mac,
         MacroStyle::Parens => {
             // Format macro invocation as function call, forcing no trailing
             // comma because not all macros support them.
-            rewrite_call(context, &macro_name, &expr_vec, mac.span, shape).map(|rw| {
-                match position {
+            rewrite_call(context, &macro_name, &expr_vec, mac.span, shape).map(
+                |rw| match position {
                     MacroPosition::Item => format!("{};", rw),
                     _ => rw,
-                }
-            })
+                },
+            )
         }
         MacroStyle::Brackets => {
             let mac_shape = try_opt!(shape.shrink_left(macro_name.len()));
@@ -199,17 +199,13 @@ pub fn rewrite_macro(mac: &ast::Mac,
             } else {
                 // Format macro invocation as array literal.
                 let rewrite =
-                    try_opt!(rewrite_array(
-                    expr_vec.iter().map(|x| &**x),
-                    mk_sp(
-                        context
-                            .codemap
-                            .span_after(mac.span, original_style.opener()),
-                        mac.span.hi - BytePos(1),
-                    ),
-                    context,
-                    mac_shape,
-                ));
+                    try_opt!(rewrite_array(expr_vec.iter().map(|x| &**x),
+                                           mk_sp(context
+                                                     .codemap
+                                                     .span_after(mac.span, original_style.opener()),
+                                               mac.span.hi - BytePos(1)),
+                                           context,
+                                           mac_shape));
 
                 Some(format!("{}{}", macro_name, rewrite))
             }
index 537e9eb7efe37746ecde6d5c15c39663fe54ae17..57ebc332ac485a4ece626cd08502d37dc5828a67 100644 (file)
@@ -22,8 +22,9 @@ fn output_at_start(&self) -> bool {
     // TODO these format_missing methods are ugly. Refactor and add unit tests
     // for the central whitespace stripping loop.
     pub fn format_missing(&mut self, end: BytePos) {
-        self.format_missing_inner(end,
-                                  |this, last_snippet, _| this.buffer.push_str(last_snippet))
+        self.format_missing_inner(end, |this, last_snippet, _| {
+            this.buffer.push_str(last_snippet)
+        })
     }
 
     pub fn format_missing_with_indent(&mut self, end: BytePos) {
index adade8910751efb46a40899ab653eaf5a1395b98..9ddfe8d6efeecd16644324d09275100048d414a7 100644 (file)
@@ -377,11 +377,12 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                     let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
                     let budget = try_opt!(shape.width.checked_sub(used_width));
                     let bounds_str: String = try_opt!(bounds
-                                                          .iter()
-                                                          .map(|ty_bound| {
-                        ty_bound.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
-                    })
-                                                          .collect::<Option<Vec<_>>>())
+                        .iter()
+                        .map(|ty_bound| {
+                            ty_bound
+                                .rewrite(context, Shape::legacy(budget, shape.indent + used_width))
+                        })
+                        .collect::<Option<Vec<_>>>())
                         .join(joiner);
 
                     if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 {
@@ -401,11 +402,12 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                     let used_width = type_str.len() + colon.len();
                     let budget = try_opt!(shape.width.checked_sub(used_width));
                     let bounds_str: String = try_opt!(bounds
-                                                          .iter()
-                                                          .map(|ty_bound| {
-                        ty_bound.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
-                    })
-                                                          .collect::<Option<Vec<_>>>())
+                        .iter()
+                        .map(|ty_bound| {
+                            ty_bound
+                                .rewrite(context, Shape::legacy(budget, shape.indent + used_width))
+                        })
+                        .collect::<Option<Vec<_>>>())
                         .join(joiner);
 
                     format!("{}{}{}", type_str, colon, bounds_str)
@@ -700,14 +702,14 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
         // This doesn't work out so nicely for mutliline situation with lots of
         // rightward drift. If that is a problem, we could use the list stuff.
         result.push_str(&try_opt!(bare_fn
-                                      .lifetimes
-                                      .iter()
-                                      .map(|l| {
-            l.rewrite(context,
-                      Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
-        })
-                                      .collect::<Option<Vec<_>>>())
-                            .join(", "));
+            .lifetimes
+            .iter()
+            .map(|l| {
+                l.rewrite(context,
+                          Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
+            })
+            .collect::<Option<Vec<_>>>())
+            .join(", "));
         result.push_str("> ");
     }