about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2017-05-01 15:48:53 +1200
committerGitHub <noreply@github.com>2017-05-01 15:48:53 +1200
commitfba5af2a7d5efa2a324b52fd80648a04d6fabb3d (patch)
tree2501011a3d42eb6a1c1341ef9438cf8cf97a7f95 /src
parenta8fbfdb4a3f3c0917e2d6a2dade42ec3f1580ca2 (diff)
parent02cf515be63600c1a2f59ba4ce77695e1ef60ceb (diff)
Merge pull request #1469 from topecongiro/bug/chains
Remove a bug when calculating the length of the chain
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs8
-rw-r--r--src/comment.rs5
-rw-r--r--src/expr.rs17
-rw-r--r--src/imports.rs5
-rw-r--r--src/items.rs18
-rw-r--r--src/lists.rs16
-rw-r--r--src/macros.rs12
-rw-r--r--src/patterns.rs10
8 files changed, 22 insertions, 69 deletions
diff --git a/src/chains.rs b/src/chains.rs
index 0181cd3d099..1460c446352 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -169,7 +169,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
     let almost_total = rewrites[..rewrites.len() - 1]
         .iter()
         .fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len();
-    let one_line_len = rewrites.iter().fold(0, |a, r| a + r.len() + 1) + parent_rewrite.len();
+    let one_line_len = rewrites.iter().fold(0, |a, r| a + r.len()) + parent_rewrite.len();
 
     let veto_single_line = if one_line_len > context.config.chain_one_line_max - 1 &&
                               rewrites.len() > 1 {
@@ -424,10 +424,8 @@ fn rewrite_method_call(method_name: ast::Ident,
     let (lo, type_str) = if types.is_empty() {
         (args[0].span.hi, String::new())
     } else {
-        let type_list: Vec<_> = try_opt!(types
-                                             .iter()
-                                             .map(|ty| ty.rewrite(context, shape))
-                                             .collect());
+        let type_list: Vec<_> =
+            try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect());
 
         let type_str = if context.config.spaces_within_angle_brackets && type_list.len() > 0 {
             format!("::< {} >", type_list.join(", "))
diff --git a/src/comment.rs b/src/comment.rs
index 3973c7fc048..9df303c86b2 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -99,10 +99,7 @@ pub fn rewrite_comment(orig: &str,
         config: config,
     };
 
-    let line_breaks = orig.trim_right()
-        .chars()
-        .filter(|&c| c == '\n')
-        .count();
+    let line_breaks = orig.trim_right().chars().filter(|&c| c == '\n').count();
     let lines = orig.lines()
         .enumerate()
         .map(|(i, mut line)| {
diff --git a/src/expr.rs b/src/expr.rs
index 7b4153083cb..fa12ad8b170 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -600,9 +600,7 @@ fn and_one_line(x: Option<String>) -> Option<String> {
 fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
     debug!("nop_block_collapse {:?} {}", block_str, budget);
     block_str.map(|block_str| if block_str.starts_with('{') && budget >= 2 &&
-                                 (block_str[1..]
-                                      .find(|c: char| !c.is_whitespace())
-                                      .unwrap() ==
+                                 (block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() ==
                                   block_str.len() - 2) {
                       "{}".to_owned()
                   } else {
@@ -933,16 +931,12 @@ impl<'a> Rewrite for ControlFlow<'a> {
 
         // for event in event
         let between_kwd_cond =
-            mk_sp(context
-                      .codemap
-                      .span_after(self.span, self.keyword.trim()),
+            mk_sp(context.codemap.span_after(self.span, self.keyword.trim()),
                   self.pat
                       .map_or(cond_span.lo, |p| if self.matcher.is_empty() {
                 p.span.lo
             } else {
-                context
-                    .codemap
-                    .span_before(self.span, self.matcher.trim())
+                context.codemap.span_before(self.span, self.matcher.trim())
             }));
 
         let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
@@ -1137,10 +1131,7 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
     let first = missed_str
         .find(|c: char| !c.is_whitespace())
         .unwrap_or(missed_str.len());
-    if missed_str[..first]
-           .chars()
-           .filter(|c| c == &'\n')
-           .count() >= 2 {
+    if missed_str[..first].chars().filter(|c| c == &'\n').count() >= 2 {
         // Excessive vertical whitespace before comment should be preserved
         // FIXME handle vertical whitespace better
         result.push('\n');
diff --git a/src/imports.rs b/src/imports.rs
index 99651159b2a..50c7b4dc938 100644
--- a/src/imports.rs
+++ b/src/imports.rs
@@ -29,10 +29,7 @@ fn path_of(a: &ast::ViewPath_) -> &ast::Path {
 }
 
 fn compare_path_segments(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
-    a.identifier
-        .name
-        .as_str()
-        .cmp(&b.identifier.name.as_str())
+    a.identifier.name.as_str().cmp(&b.identifier.name.as_str())
 }
 
 fn compare_paths(a: &ast::Path, b: &ast::Path) -> Ordering {
diff --git a/src/items.rs b/src/items.rs
index 2cb4e46ecb5..9ab551ddccc 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -242,9 +242,7 @@ impl<'a> FmtVisitor<'a> {
         let context = self.get_context();
 
         let block_snippet = self.snippet(codemap::mk_sp(block.span.lo, block.span.hi));
-        let has_body = !block_snippet[1..block_snippet.len() - 1]
-                            .trim()
-                            .is_empty() ||
+        let has_body = !block_snippet[1..block_snippet.len() - 1].trim().is_empty() ||
                        !context.config.fn_empty_single_line;
 
         let (mut result, force_newline_brace) = try_opt!(rewrite_fn_base(&context,
@@ -1227,10 +1225,7 @@ impl Rewrite for ast::StructField {
 
         let type_offset = shape.indent.block_indent(context.config);
         let rewrite_type_in_next_line = || {
-            let budget = try_opt!(context
-                                      .config
-                                      .max_width
-                                      .checked_sub(type_offset.width()));
+            let budget = try_opt!(context.config.max_width.checked_sub(type_offset.width()));
             self.ty
                 .rewrite(context, Shape::legacy(budget, type_offset))
         };
@@ -1624,9 +1619,7 @@ fn rewrite_fn_base(context: &RewriteContext,
         .ty_params
         .last()
         .map_or(span.lo, |tp| end_typaram(tp));
-    let args_span = mk_sp(context
-                              .codemap
-                              .span_after(mk_sp(args_start, span.hi), "("),
+    let args_span = mk_sp(context.codemap.span_after(mk_sp(args_start, span.hi), "("),
                           span_for_return(&fd.output).lo);
     let arg_str = try_opt!(rewrite_args(context,
                                         &fd.inputs,
@@ -1767,10 +1760,7 @@ fn rewrite_fn_base(context: &RewriteContext,
         }
     }
 
-    let budget = try_opt!(context
-                              .config
-                              .max_width
-                              .checked_sub(indent.block_indent));
+    let budget = try_opt!(context.config.max_width.checked_sub(indent.block_indent));
     let where_clause_str = try_opt!(rewrite_where_clause(context,
                                                          where_clause,
                                                          context.config.fn_brace_style,
diff --git a/src/lists.rs b/src/lists.rs
index 6b917ff29e6..7933ebab807 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -172,9 +172,7 @@ pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> De
     let real_total = total_width + total_sep_len;
 
     if real_total <= limit && !pre_line_comments &&
-       !items
-            .into_iter()
-            .any(|item| item.as_ref().is_multiline()) {
+       !items.into_iter().any(|item| item.as_ref().is_multiline()) {
         DefinitiveListTactic::Horizontal
     } else {
         DefinitiveListTactic::Vertical
@@ -536,10 +534,7 @@ pub fn struct_lit_shape(shape: Shape,
         IndentStyle::Block => {
             let shape = shape.block_indent(context.config.tab_spaces);
             Shape {
-                width: try_opt!(context
-                                    .config
-                                    .max_width
-                                    .checked_sub(shape.indent.width())),
+                width: try_opt!(context.config.max_width.checked_sub(shape.indent.width())),
                 ..shape
             }
         }
@@ -556,12 +551,7 @@ pub fn struct_lit_tactic(h_shape: Option<Shape>,
     if let Some(h_shape) = h_shape {
         let mut prelim_tactic = match (context.config.struct_lit_style, items.len()) {
             (IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
-            _ => {
-                context
-                    .config
-                    .struct_lit_multiline_style
-                    .to_list_tactic()
-            }
+            _ => context.config.struct_lit_multiline_style.to_list_tactic(),
         };
 
         if prelim_tactic == ListTactic::HorizontalVertical && items.len() > 1 {
diff --git a/src/macros.rs b/src/macros.rs
index fd5578e7f00..f7f6eb19727 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -196,15 +196,9 @@ pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option<ast::
 
 fn macro_style(mac: &ast::Mac, context: &RewriteContext) -> MacroStyle {
     let snippet = context.snippet(mac.span);
-    let paren_pos = snippet
-        .find_uncommented("(")
-        .unwrap_or(usize::max_value());
-    let bracket_pos = snippet
-        .find_uncommented("[")
-        .unwrap_or(usize::max_value());
-    let brace_pos = snippet
-        .find_uncommented("{")
-        .unwrap_or(usize::max_value());
+    let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value());
+    let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value());
+    let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::max_value());
 
     if paren_pos < bracket_pos && paren_pos < brace_pos {
         MacroStyle::Parens
diff --git a/src/patterns.rs b/src/patterns.rs
index 1ed13ab70b6..a50fee040d6 100644
--- a/src/patterns.rs
+++ b/src/patterns.rs
@@ -102,10 +102,8 @@ impl Rewrite for Pat {
                 let suffix = suffix.iter().map(|p| p.rewrite(context, shape));
 
                 // Munge them together.
-                let pats: Option<Vec<String>> = prefix
-                    .chain(slice_pat.into_iter())
-                    .chain(suffix)
-                    .collect();
+                let pats: Option<Vec<String>> =
+                    prefix.chain(slice_pat.into_iter()).chain(suffix).collect();
 
                 // Check that all the rewrites succeeded, and if not return None.
                 let pats = try_opt!(pats);
@@ -244,9 +242,7 @@ fn rewrite_tuple_pat(pats: &[ptr::P<ast::Pat>],
                      context: &RewriteContext,
                      shape: Shape)
                      -> Option<String> {
-    let mut pat_vec: Vec<_> = pats.into_iter()
-        .map(|x| TuplePatField::Pat(x))
-        .collect();
+    let mut pat_vec: Vec<_> = pats.into_iter().map(|x| TuplePatField::Pat(x)).collect();
 
     if let Some(pos) = dotdot_pos {
         let prev = if pos == 0 {