about summary refs log tree commit diff
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-25 16:08:08 +0900
committertopecongiro <seuchida@gmail.com>2017-05-25 16:08:08 +0900
commit86856491bc3457bd2abe66359a4f63cc6cbd0769 (patch)
tree94e6143822dcff66731f1f0e67a0d51c902b62da
parent2580d7a3107b99fb7cc43dd19d833396f2522e9f (diff)
Format source codes
-rw-r--r--src/config.rs2
-rw-r--r--src/expr.rs33
-rw-r--r--src/file_lines.rs3
-rw-r--r--src/items.rs3
-rw-r--r--src/lists.rs6
-rw-r--r--src/macros.rs11
-rw-r--r--src/modules.rs3
-rw-r--r--src/string.rs3
-rw-r--r--src/utils.rs3
-rw-r--r--tests/system.rs9
10 files changed, 31 insertions, 45 deletions
diff --git a/src/config.rs b/src/config.rs
index c64d2c0647d..0c73b64c6b2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -448,6 +448,8 @@ create_config! {
         "Report all, none or unnumbered occurrences of FIXME in source file comments";
     chain_indent: IndentStyle, IndentStyle::Block, "Indentation of chain";
     chain_one_line_max: usize, 60, "Maximum length of a chain to fit on a single line";
+    chain_split_single_child: bool, false, "Split a chain with a single child if its length \
+                                            exceeds `chain_one_line_max`";
     reorder_imports: bool, false, "Reorder import statements alphabetically";
     reorder_imports_in_group: bool, false, "Reorder import statements in group";
     reorder_imported_names: bool, false,
diff --git a/src/expr.rs b/src/expr.rs
index 07f1c80fc3d..4a415a5cc82 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -98,20 +98,16 @@ fn format_expr(expr: &ast::Expr,
         }
         ast::ExprKind::Tup(ref items) => rewrite_tuple(context, items, expr.span, shape),
         ast::ExprKind::While(ref cond, ref block, label) => {
-            ControlFlow::new_while(None, cond, block, label, expr.span)
-                .rewrite(context, shape)
+            ControlFlow::new_while(None, cond, block, label, expr.span).rewrite(context, shape)
         }
         ast::ExprKind::WhileLet(ref pat, ref cond, ref block, label) => {
-            ControlFlow::new_while(Some(pat), cond, block, label, expr.span)
-                .rewrite(context, shape)
+            ControlFlow::new_while(Some(pat), cond, block, label, expr.span).rewrite(context, shape)
         }
         ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => {
-            ControlFlow::new_for(pat, cond, block, label, expr.span)
-                .rewrite(context, shape)
+            ControlFlow::new_for(pat, cond, block, label, expr.span).rewrite(context, shape)
         }
         ast::ExprKind::Loop(ref block, label) => {
-            ControlFlow::new_loop(block, label, expr.span)
-                .rewrite(context, shape)
+            ControlFlow::new_loop(block, label, expr.span).rewrite(context, shape)
         }
         ast::ExprKind::Block(ref block) => block.rewrite(context, shape),
         ast::ExprKind::If(ref cond, ref if_block, ref else_block) => {
@@ -179,12 +175,11 @@ fn format_expr(expr: &ast::Expr,
         ast::ExprKind::Mac(ref mac) => {
             // Failure to rewrite a marco should not imply failure to
             // rewrite the expression.
-            rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
-                .or_else(|| {
-                             wrap_str(context.snippet(expr.span),
-                                      context.config.max_width(),
-                                      shape)
-                         })
+            rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
+                wrap_str(context.snippet(expr.span),
+                         context.config.max_width(),
+                         shape)
+            })
         }
         ast::ExprKind::Ret(None) => {
             wrap_str("return".to_owned(), context.config.max_width(), shape)
@@ -324,8 +319,7 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
                                   .checked_sub(shape.used_width() + prefix.len() + infix.len()));
     let rhs_shape = match context.config.control_style() {
         Style::Default => {
-            try_opt!(shape.sub_width(suffix.len() + prefix.len()))
-                .visual_indent(prefix.len())
+            try_opt!(shape.sub_width(suffix.len() + prefix.len())).visual_indent(prefix.len())
         }
         Style::Rfc => try_opt!(shape.block_left(context.config.tab_spaces())),
     };
@@ -516,8 +510,7 @@ fn rewrite_closure(capture: ast::CaptureBy,
 
     // 1 = space between `|...|` and body.
     let extra_offset = extra_offset(&prefix, shape) + 1;
-    let body_shape = try_opt!(shape.sub_width(extra_offset))
-        .add_offset(extra_offset);
+    let body_shape = try_opt!(shape.sub_width(extra_offset)).add_offset(extra_offset);
 
     if let ast::ExprKind::Block(ref block) = body.node {
         // The body of the closure is an empty block.
@@ -859,8 +852,8 @@ impl<'a> ControlFlow<'a> {
 
             let new_width = try_opt!(new_width.checked_sub(if_str.len()));
             let else_expr = &else_node.stmts[0];
-            let else_str = try_opt!(else_expr.rewrite(context,
-                                                      Shape::legacy(new_width, Indent::empty())));
+            let else_str =
+                try_opt!(else_expr.rewrite(context, Shape::legacy(new_width, Indent::empty())));
 
             if if_str.contains('\n') || else_str.contains('\n') {
                 return None;
diff --git a/src/file_lines.rs b/src/file_lines.rs
index 9de427781fe..2d1fa33a90e 100644
--- a/src/file_lines.rs
+++ b/src/file_lines.rs
@@ -135,8 +135,7 @@ impl FileLines {
             Some(ref map) => map,
         };
 
-        match canonicalize_path_string(file_name)
-                  .and_then(|file| map.get(&file)) {
+        match canonicalize_path_string(file_name).and_then(|file| map.get(&file)) {
             Some(ranges) => ranges.iter().any(f),
             None => false,
         }
diff --git a/src/items.rs b/src/items.rs
index 88e663403d6..37ffb4792eb 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1125,8 +1125,7 @@ pub fn rewrite_type_alias(context: &RewriteContext,
 
     let generics_indent = indent + result.len();
     let generics_span = mk_sp(context.codemap.span_after(span, "type"), ty.span.lo);
-    let shape = try_opt!(Shape::indented(generics_indent, context.config)
-                             .sub_width(" =".len()));
+    let shape = try_opt!(Shape::indented(generics_indent, context.config).sub_width(" =".len()));
     let generics_str = try_opt!(rewrite_generics(context, generics, shape, generics_span));
 
     result.push_str(&generics_str);
diff --git a/src/lists.rs b/src/lists.rs
index adc18c14581..3448f8a446a 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -430,8 +430,7 @@ impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
             let post_snippet_trimmed = if post_snippet.starts_with(',') {
                 post_snippet[1..].trim_matches(white_space)
             } else if post_snippet.ends_with(',') {
-                post_snippet[..(post_snippet.len() - 1)]
-                    .trim_matches(white_space)
+                post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
             } else {
                 post_snippet
             };
@@ -529,8 +528,7 @@ pub fn struct_lit_shape(shape: Shape,
                         -> Option<(Option<Shape>, Shape)> {
     let v_shape = match context.config.struct_lit_style() {
         IndentStyle::Visual => {
-            try_opt!(try_opt!(shape.shrink_left(prefix_width))
-                         .sub_width(suffix_width))
+            try_opt!(try_opt!(shape.shrink_left(prefix_width)).sub_width(suffix_width))
         }
         IndentStyle::Block => {
             let shape = shape.block_indent(context.config.tab_spaces());
diff --git a/src/macros.rs b/src/macros.rs
index c46ed3d88c7..3c6c54f42cf 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -172,11 +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 {
-                         MacroPosition::Item => format!("{};", rw),
-                         _ => rw,
-                     })
+            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()));
diff --git a/src/modules.rs b/src/modules.rs
index 5e09a311dcb..3d2c3b0ac9f 100644
--- a/src/modules.rs
+++ b/src/modules.rs
@@ -68,8 +68,7 @@ fn module_file(id: ast::Ident,
         return path;
     }
 
-    match parser::Parser::default_submod_path(id, dir_path, codemap)
-              .result {
+    match parser::Parser::default_submod_path(id, dir_path, codemap).result {
         Ok(parser::ModulePathSuccess { path, .. }) => path,
         Err(_) => panic!("Couldn't find module {}", id),
     }
diff --git a/src/string.rs b/src/string.rs
index 17c6533f7a0..365d205aef1 100644
--- a/src/string.rs
+++ b/src/string.rs
@@ -35,8 +35,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
     let re = Regex::new(r"([^\\](\\\\)*)\\[\n\r][[:space:]]*").unwrap();
     let stripped_str = re.replace_all(orig, "$1");
 
-    let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false)
-        .collect::<Vec<&str>>();
+    let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
     let shape = fmt.shape.visual_indent(0);
     let indent = shape.indent.to_string(fmt.config);
     let punctuation = ":,;.";
diff --git a/src/utils.rs b/src/utils.rs
index 1192608c24a..e80c558e51e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -332,8 +332,7 @@ pub fn wrap_str<S: AsRef<str>>(s: S, max_width: usize, shape: Shape) -> Option<S
 
 impl Rewrite for String {
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
-        wrap_str(self, context.config.max_width(), shape)
-            .map(ToOwned::to_owned)
+        wrap_str(self, context.config.max_width(), shape).map(ToOwned::to_owned)
     }
 }
 
diff --git a/tests/system.rs b/tests/system.rs
index 70c8033da6c..58e44ee5381 100644
--- a/tests/system.rs
+++ b/tests/system.rs
@@ -55,8 +55,7 @@ fn system_tests() {
 // the only difference is the coverage mode
 #[test]
 fn coverage_tests() {
-    let files = fs::read_dir("tests/coverage/source")
-        .expect("Couldn't read source dir");
+    let files = fs::read_dir("tests/coverage/source").expect("Couldn't read source dir");
     let files = files.map(get_path_string);
     let (_reports, count, fails) = check_files(files);
 
@@ -83,8 +82,7 @@ fn assert_output(source: &str, expected_filename: &str) {
     let _ = filemap::write_all_files(&file_map, &mut out, &config);
     let output = String::from_utf8(out).unwrap();
 
-    let mut expected_file = fs::File::open(&expected_filename)
-        .expect("Couldn't open target");
+    let mut expected_file = fs::File::open(&expected_filename).expect("Couldn't open target");
     let mut expected_text = String::new();
     expected_file
         .read_to_string(&mut expected_text)
@@ -279,8 +277,7 @@ fn get_config(config_file: Option<&str>) -> Config {
         }
     };
 
-    let mut def_config_file = fs::File::open(config_file_name)
-        .expect("Couldn't open config");
+    let mut def_config_file = fs::File::open(config_file_name).expect("Couldn't open config");
     let mut def_config = String::new();
     def_config_file
         .read_to_string(&mut def_config)