about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2017-06-13 14:49:47 +1200
committerNick Cameron <ncameron@mozilla.com>2017-06-13 14:49:47 +1200
commit18ccd0190ee6ef4a6e1bb9d737e515b872009711 (patch)
tree975ea2d02abb8da3ad0222684606c6e2b2c4e1ef /src
parent6f30d9e7c973d7bee78f8d16aa623f679c37bcae (diff)
Rebasing
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs3
-rw-r--r--src/expr.rs144
-rw-r--r--src/items.rs323
-rw-r--r--src/lib.rs6
-rw-r--r--src/lists.rs26
-rw-r--r--src/patterns.rs3
-rw-r--r--src/string.rs10
-rw-r--r--src/types.rs76
8 files changed, 343 insertions, 248 deletions
diff --git a/src/chains.rs b/src/chains.rs
index eba79505e20..890c39ebabb 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -574,7 +574,8 @@ fn rewrite_method_call(
     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/expr.rs b/src/expr.rs
index 24432fb1dff..80c89a3a91b 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -281,7 +281,9 @@ fn format_expr(
             Some(format!(
                 "{}{}",
                 "do catch ",
-                try_opt!(block.rewrite(&context, Shape::legacy(budget, shape.indent)))
+                try_opt!(
+                    block.rewrite(&context, Shape::legacy(budget, shape.indent))
+                )
             ))
         }
     };
@@ -1428,9 +1430,11 @@ impl Rewrite for ast::Arm {
             if contains_skip(attrs) {
                 return None;
             }
-            format!("{}\n{}",
-                    try_opt!(attrs.rewrite(context, shape)),
-                    shape.indent.to_string(context.config))
+            format!(
+                "{}\n{}",
+                try_opt!(attrs.rewrite(context, shape)),
+                shape.indent.to_string(context.config)
+            )
         } else {
             String::new()
         };
@@ -1515,11 +1519,11 @@ impl Rewrite for ast::Arm {
             };
 
             match rewrite {
-                Some(ref body_str) if (!body_str.contains('\n') &&
-                                           body_str.len() <= arm_shape.width) ||
-                                          !context.config.wrap_match_arms() ||
-                                          (extend && first_line_width(body_str) <= arm_shape.width) ||
-                                          is_block => {
+                Some(ref body_str)
+                    if (!body_str.contains('\n') && body_str.len() <= arm_shape.width) ||
+                           !context.config.wrap_match_arms() ||
+                           (extend && first_line_width(body_str) <= arm_shape.width) ||
+                           is_block => {
                     let block_sep = match context.config.control_brace_style() {
                         ControlBraceStyle::AlwaysNextLine if is_block => alt_block_sep.as_str(),
                         _ => " ",
@@ -1610,28 +1614,33 @@ fn rewrite_guard(
     if let Some(ref guard) = *guard {
         // First try to fit the guard string on the same line as the pattern.
         // 4 = ` if `, 5 = ` => {`
-        if let Some(cond_shape) = shape
-               .shrink_left(pattern_width + 4)
-               .and_then(|s| s.sub_width(5)) {
-            if let Some(cond_str) = guard
-                   .rewrite(context, cond_shape)
-                   .and_then(|s| s.rewrite(context, cond_shape)) {
+        if let Some(cond_shape) = shape.shrink_left(pattern_width + 4).and_then(
+            |s| s.sub_width(5),
+        )
+        {
+            if let Some(cond_str) = guard.rewrite(context, cond_shape).and_then(|s| {
+                s.rewrite(context, cond_shape)
+            })
+            {
                 return Some(format!(" if {}", cond_str));
             }
         }
 
         // Not enough space to put the guard after the pattern, try a newline.
         // 3 == `if `
-        if let Some(cond_shape) = Shape::indented(shape.indent.block_indent(context.config) + 3,
-                                                  context.config)
-               .sub_width(3) {
+        if let Some(cond_shape) = Shape::indented(
+            shape.indent.block_indent(context.config) + 3,
+            context.config,
+        ).sub_width(3)
+        {
             if let Some(cond_str) = guard.rewrite(context, cond_shape) {
-                return Some(format!("\n{}if {}",
-                                    shape
-                                        .indent
-                                        .block_indent(context.config)
-                                        .to_string(context.config),
-                                    cond_str));
+                return Some(format!(
+                    "\n{}if {}",
+                    shape.indent.block_indent(context.config).to_string(
+                        context.config,
+                    ),
+                    cond_str
+                ));
             }
         }
 
@@ -1826,26 +1835,28 @@ fn rewrite_call_inner(
     let span_lo = context.codemap.span_after(span, "(");
     let args_span = mk_sp(span_lo, span.hi);
 
-    let (extendable, list_str) = rewrite_call_args(context,
-                                                   args,
-                                                   args_span,
-                                                   nested_shape,
-                                                   one_line_width,
-                                                   force_trailing_comma)
-        .or_else(|| if context.use_block_indent() {
-                     rewrite_call_args(context,
-                                       args,
-                                       args_span,
-                                       Shape::indented(shape
-                                                           .block()
-                                                           .indent
-                                                           .block_indent(context.config),
-                                                       context.config),
-                                       0,
-                                       force_trailing_comma)
-                 } else {
-                     None
-                 })
+    let (extendable, list_str) = rewrite_call_args(
+        context,
+        args,
+        args_span,
+        nested_shape,
+        one_line_width,
+        force_trailing_comma,
+    ).or_else(|| if context.use_block_indent() {
+        rewrite_call_args(
+            context,
+            args,
+            args_span,
+            Shape::indented(
+                shape.block().indent.block_indent(context.config),
+                context.config,
+            ),
+            0,
+            force_trailing_comma,
+        )
+    } else {
+        None
+    })
         .ok_or(Ordering::Less)?;
 
     if !context.use_block_indent() && need_block_indent(&list_str, nested_shape) && !extendable {
@@ -1861,12 +1872,20 @@ fn rewrite_call_inner(
         );
     }
 
-    let args_shape = shape
-        .sub_width(last_line_width(&callee_str))
-        .ok_or(Ordering::Less)?;
-    Ok(format!("{}{}",
-               callee_str,
-               wrap_args_with_parens(context, &list_str, extendable, args_shape, nested_shape)))
+    let args_shape = shape.sub_width(last_line_width(&callee_str)).ok_or(
+        Ordering::Less,
+    )?;
+    Ok(format!(
+        "{}{}",
+        callee_str,
+        wrap_args_with_parens(
+            context,
+            &list_str,
+            extendable,
+            args_shape,
+            nested_shape,
+        )
+    ))
 }
 
 fn need_block_indent(s: &str, shape: Shape) -> bool {
@@ -2056,15 +2075,17 @@ fn paren_overhead(context: &RewriteContext) -> usize {
     }
 }
 
-fn wrap_args_with_parens(context: &RewriteContext,
-                         args_str: &str,
-                         is_extendable: bool,
-                         shape: Shape,
-                         nested_shape: Shape)
-                         -> String {
+fn wrap_args_with_parens(
+    context: &RewriteContext,
+    args_str: &str,
+    is_extendable: bool,
+    shape: Shape,
+    nested_shape: Shape,
+) -> String {
     if !context.use_block_indent() ||
-       (context.inside_macro && !args_str.contains('\n') &&
-        args_str.len() + paren_overhead(context) <= shape.width) || is_extendable {
+        (context.inside_macro && !args_str.contains('\n') &&
+             args_str.len() + paren_overhead(context) <= shape.width) || is_extendable
+    {
         if context.config.spaces_within_parens() && args_str.len() > 0 {
             format!("( {} )", args_str)
         } else {
@@ -2166,10 +2187,9 @@ fn rewrite_struct_lit<'a>(
         return Some(format!("{} {{}}", path_str));
     }
 
-    let field_iter = fields
-        .into_iter()
-        .map(StructLitField::Regular)
-        .chain(base.into_iter().map(StructLitField::Base));
+    let field_iter = fields.into_iter().map(StructLitField::Regular).chain(
+        base.into_iter().map(StructLitField::Base),
+    );
 
     // Foo { a: Foo } - indent is +3, width is -5.
     let (h_shape, v_shape) = try_opt!(struct_lit_shape(shape, context, path_str.len() + 3, 2));
diff --git a/src/items.rs b/src/items.rs
index 01aa7b389d5..156528301be 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -550,11 +550,12 @@ impl<'a> FmtVisitor<'a> {
     }
 }
 
-pub fn format_impl(context: &RewriteContext,
-                   item: &ast::Item,
-                   offset: Indent,
-                   where_span_end: Option<BytePos>)
-                   -> Option<String> {
+pub fn format_impl(
+    context: &RewriteContext,
+    item: &ast::Item,
+    offset: Indent,
+    where_span_end: Option<BytePos>,
+) -> Option<String> {
     if let ast::ItemKind::Impl(_, _, _, ref generics, _, _, ref items) = item.node {
         let mut result = String::new();
         let ref_and_type = try_opt!(format_impl_ref_and_type(context, item, offset));
@@ -569,18 +570,26 @@ pub fn format_impl(context: &RewriteContext,
                 .checked_sub(last_line_width(&result))
                 .unwrap_or(0)
         };
-        let where_clause_str = try_opt!(rewrite_where_clause(context,
-                                                             &generics.where_clause,
-                                                             context.config.item_brace_style(),
-                                                             Shape::legacy(where_budget,
-                                                                           offset.block_only()),
-                                                             context.config.where_density(),
-                                                             "{",
-                                                             false,
-                                                             last_line_width(&ref_and_type) == 1,
-                                                             where_span_end));
-
-        if try_opt!(is_impl_single_line(context, &items, &result, &where_clause_str, &item)) {
+        let where_clause_str = try_opt!(rewrite_where_clause(
+            context,
+            &generics.where_clause,
+            context.config.item_brace_style(),
+            Shape::legacy(where_budget, offset.block_only()),
+            context.config.where_density(),
+            "{",
+            false,
+            last_line_width(&ref_and_type) == 1,
+            where_span_end,
+        ));
+
+        if try_opt!(is_impl_single_line(
+            context,
+            &items,
+            &result,
+            &where_clause_str,
+            &item,
+        ))
+        {
             result.push_str(&where_clause_str);
             if where_clause_str.contains('\n') {
                 let white_space = offset.to_string(context.config);
@@ -670,10 +679,11 @@ fn is_impl_single_line(
     )
 }
 
-fn format_impl_ref_and_type(context: &RewriteContext,
-                            item: &ast::Item,
-                            offset: Indent)
-                            -> Option<String> {
+fn format_impl_ref_and_type(
+    context: &RewriteContext,
+    item: &ast::Item,
+    offset: Indent,
+) -> Option<String> {
     if let ast::ItemKind::Impl(unsafety,
                             polarity,
                             _,
@@ -693,12 +703,18 @@ fn format_impl_ref_and_type(context: &RewriteContext,
             Some(ref tr) => tr.path.span.lo,
             None => self_ty.span.lo,
         };
-        let shape = generics_shape_from_config(context.config,
-                                               Shape::indented(offset + last_line_width(&result),
-                                                               context.config),
-                                               0);
-        let generics_str =
-            try_opt!(rewrite_generics_inner(context, generics, shape, shape.width, mk_sp(lo, hi)));
+        let shape = generics_shape_from_config(
+            context.config,
+            Shape::indented(offset + last_line_width(&result), context.config),
+            0,
+        );
+        let generics_str = try_opt!(rewrite_generics_inner(
+            context,
+            generics,
+            shape,
+            shape.width,
+            mk_sp(lo, hi),
+        ));
 
         let polarity_str = if polarity == ast::ImplPolarity::Negative {
             "!"
@@ -709,24 +725,34 @@ fn format_impl_ref_and_type(context: &RewriteContext,
         if let Some(ref trait_ref) = *trait_ref {
             let result_len = result.len();
             if let Some(trait_ref_str) =
-                rewrite_trait_ref(context,
-                                  &trait_ref,
-                                  offset,
-                                  &generics_str,
-                                  true,
-                                  polarity_str,
-                                  result_len) {
+                rewrite_trait_ref(
+                    context,
+                    &trait_ref,
+                    offset,
+                    &generics_str,
+                    true,
+                    polarity_str,
+                    result_len,
+                )
+            {
                 result.push_str(&trait_ref_str);
             } else {
-                let generics_str =
-                    try_opt!(rewrite_generics_inner(context, generics, shape, 0, mk_sp(lo, hi)));
-                result.push_str(&try_opt!(rewrite_trait_ref(context,
-                                                            &trait_ref,
-                                                            offset,
-                                                            &generics_str,
-                                                            false,
-                                                            polarity_str,
-                                                            result_len)));
+                let generics_str = try_opt!(rewrite_generics_inner(
+                    context,
+                    generics,
+                    shape,
+                    0,
+                    mk_sp(lo, hi),
+                ));
+                result.push_str(&try_opt!(rewrite_trait_ref(
+                    context,
+                    &trait_ref,
+                    offset,
+                    &generics_str,
+                    false,
+                    polarity_str,
+                    result_len,
+                )));
             }
         } else {
             result.push_str(&generics_str);
@@ -777,32 +803,41 @@ fn format_impl_ref_and_type(context: &RewriteContext,
             Style::Legacy => new_line_offset + trait_ref_overhead,
             Style::Rfc => new_line_offset,
         };
-        result.push_str(&*try_opt!(self_ty.rewrite(context, Shape::legacy(budget, type_offset))));
+        result.push_str(&*try_opt!(self_ty.rewrite(
+            context,
+            Shape::legacy(budget, type_offset),
+        )));
         Some(result)
     } else {
         unreachable!();
     }
 }
 
-fn rewrite_trait_ref(context: &RewriteContext,
-                     trait_ref: &ast::TraitRef,
-                     offset: Indent,
-                     generics_str: &str,
-                     retry: bool,
-                     polarity_str: &str,
-                     result_len: usize)
-                     -> Option<String> {
+fn rewrite_trait_ref(
+    context: &RewriteContext,
+    trait_ref: &ast::TraitRef,
+    offset: Indent,
+    generics_str: &str,
+    retry: bool,
+    polarity_str: &str,
+    result_len: usize,
+) -> Option<String> {
     // 1 = space between generics and trait_ref
     let used_space = 1 + polarity_str.len() +
-                     if generics_str.contains('\n') {
-                         last_line_width(&generics_str)
-                     } else {
-                         result_len + generics_str.len()
-                     };
+        if generics_str.contains('\n') {
+            last_line_width(&generics_str)
+        } else {
+            result_len + generics_str.len()
+        };
     let shape = Shape::indented(offset + used_space, context.config);
     if let Some(trait_ref_str) = trait_ref.rewrite(context, shape) {
         if !(retry && trait_ref_str.contains('\n')) {
-            return Some(format!("{} {}{}", generics_str, polarity_str, &trait_ref_str));
+            return Some(format!(
+                "{} {}{}",
+                generics_str,
+                polarity_str,
+                &trait_ref_str
+            ));
         }
     }
     // We could not make enough space for trait_ref, so put it on new line.
@@ -810,26 +845,29 @@ fn rewrite_trait_ref(context: &RewriteContext,
         let offset = offset.block_indent(context.config);
         let shape = Shape::indented(offset, context.config);
         let trait_ref_str = try_opt!(trait_ref.rewrite(context, shape));
-        Some(format!("{}\n{}{}{}",
-                     generics_str,
-                     &offset.to_string(context.config),
-                     polarity_str,
-                     &trait_ref_str))
+        Some(format!(
+            "{}\n{}{}{}",
+            generics_str,
+            &offset.to_string(context.config),
+            polarity_str,
+            &trait_ref_str
+        ))
     } else {
         None
     }
 }
 
-pub fn format_struct(context: &RewriteContext,
-                     item_name: &str,
-                     ident: ast::Ident,
-                     vis: &ast::Visibility,
-                     struct_def: &ast::VariantData,
-                     generics: Option<&ast::Generics>,
-                     span: Span,
-                     offset: Indent,
-                     one_line_width: Option<usize>)
-                     -> Option<String> {
+pub fn format_struct(
+    context: &RewriteContext,
+    item_name: &str,
+    ident: ast::Ident,
+    vis: &ast::Visibility,
+    struct_def: &ast::VariantData,
+    generics: Option<&ast::Generics>,
+    span: Span,
+    offset: Indent,
+    one_line_width: Option<usize>,
+) -> Option<String> {
     match *struct_def {
         ast::VariantData::Unit(..) => Some(format_unit_struct(item_name, ident, vis)),
         ast::VariantData::Tuple(ref fields, _) => {
@@ -877,8 +915,12 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
         let body_lo = context.codemap.span_after(item.span, "{");
 
         let shape = Shape::indented(offset + last_line_width(&result), context.config);
-        let generics_str =
-            try_opt!(rewrite_generics(context, generics, shape, mk_sp(item.span.lo, body_lo)));
+        let generics_str = try_opt!(rewrite_generics(
+            context,
+            generics,
+            shape,
+            mk_sp(item.span.lo, body_lo),
+        ));
         result.push_str(&generics_str);
 
         let trait_bound_str = try_opt!(rewrite_trait_bounds(
@@ -1534,10 +1576,12 @@ pub fn rewrite_associated_type(
     let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
         let shape = Shape::legacy(context.config.max_width(), indent);
         let bounds: &[_] = ty_param_bounds;
-        let bound_str = try_opt!(bounds
-                                     .iter()
-                                     .map(|ty_bound| ty_bound.rewrite(context, shape))
-                                     .collect::<Option<Vec<_>>>());
+        let bound_str = try_opt!(
+            bounds
+                .iter()
+                .map(|ty_bound| ty_bound.rewrite(context, shape))
+                .collect::<Option<Vec<_>>>()
+        );
         if bounds.len() > 0 {
             format!(": {}", join_bounds(context, shape, &bound_str))
         } else {
@@ -2269,7 +2313,8 @@ fn compute_budgets_for_args(
             // 4 = "() {".len()
             let multi_line_overhead = indent.width() + result.len() +
                 if newline_brace { 2 } else { 4 };
-            let multi_line_budget = try_opt!(context.config.max_width().checked_sub(multi_line_overhead));
+            let multi_line_budget =
+                try_opt!(context.config.max_width().checked_sub(multi_line_overhead));
 
             return Some((
                 one_line_budget,
@@ -2295,22 +2340,24 @@ fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause) -> bool {
     }
 }
 
-fn rewrite_generics(context: &RewriteContext,
-                    generics: &ast::Generics,
-                    shape: Shape,
-                    span: Span)
-                    -> Option<String> {
+fn rewrite_generics(
+    context: &RewriteContext,
+    generics: &ast::Generics,
+    shape: Shape,
+    span: Span,
+) -> Option<String> {
     let shape = generics_shape_from_config(context.config, shape, 0);
     rewrite_generics_inner(context, generics, shape, shape.width, span)
         .or_else(|| rewrite_generics_inner(context, generics, shape, 0, span))
 }
 
-fn rewrite_generics_inner(context: &RewriteContext,
-                          generics: &ast::Generics,
-                          shape: Shape,
-                          one_line_width: usize,
-                          span: Span)
-                          -> Option<String> {
+fn rewrite_generics_inner(
+    context: &RewriteContext,
+    generics: &ast::Generics,
+    shape: Shape,
+    one_line_width: usize,
+    span: Span,
+) -> Option<String> {
     // FIXME: convert bounds to where clauses where they get too big or if
     // there is a where clause at all.
     let lifetimes: &[_] = &generics.lifetimes;
@@ -2334,15 +2381,17 @@ fn rewrite_generics_inner(context: &RewriteContext,
     });
     let ty_spans = tys.iter().map(span_for_ty_param);
 
-    let items = itemize_list(context.codemap,
-                             lt_spans.chain(ty_spans).zip(lt_strs.chain(ty_strs)),
-                             ">",
-                             |&(sp, _)| sp.lo,
-                             |&(sp, _)| sp.hi,
-                             // FIXME: don't clone
-                             |&(_, ref str)| str.clone(),
-                             context.codemap.span_after(span, "<"),
-                             span.hi);
+    let items = itemize_list(
+        context.codemap,
+        lt_spans.chain(ty_spans).zip(lt_strs.chain(ty_strs)),
+        ">",
+        |&(sp, _)| sp.lo,
+        |&(sp, _)| sp.hi,
+        // FIXME: don't clone
+        |&(_, ref str)| str.clone(),
+        context.codemap.span_after(span, "<"),
+        span.hi,
+    );
     format_generics_item_list(context, items, shape, one_line_width)
 }
 
@@ -2357,12 +2406,14 @@ pub fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize)
     }
 }
 
-pub fn format_generics_item_list<I>(context: &RewriteContext,
-                                    items: I,
-                                    shape: Shape,
-                                    one_line_budget: usize)
-                                    -> Option<String>
-    where I: Iterator<Item = ListItem>
+pub fn format_generics_item_list<I>(
+    context: &RewriteContext,
+    items: I,
+    shape: Shape,
+    one_line_budget: usize,
+) -> Option<String>
+where
+    I: Iterator<Item = ListItem>,
 {
     let item_vec = items.collect::<Vec<_>>();
 
@@ -2381,21 +2432,29 @@ pub fn format_generics_item_list<I>(context: &RewriteContext,
 
     let list_str = try_opt!(write_list(&item_vec, &fmt));
 
-    Some(wrap_generics_with_angle_brackets(context, &list_str, shape.indent))
+    Some(wrap_generics_with_angle_brackets(
+        context,
+        &list_str,
+        shape.indent,
+    ))
 }
 
-pub fn wrap_generics_with_angle_brackets(context: &RewriteContext,
-                                         list_str: &str,
-                                         list_offset: Indent)
-                                         -> String {
+pub fn wrap_generics_with_angle_brackets(
+    context: &RewriteContext,
+    list_str: &str,
+    list_offset: Indent,
+) -> String {
     if context.config.generics_indent() == IndentStyle::Block &&
-       (list_str.contains('\n') || list_str.ends_with(',')) {
-        format!("<\n{}{}\n{}>",
-                list_offset.to_string(context.config),
-                list_str,
-                list_offset
-                    .block_unindent(context.config)
-                    .to_string(context.config))
+        (list_str.contains('\n') || list_str.ends_with(','))
+    {
+        format!(
+            "<\n{}{}\n{}>",
+            list_offset.to_string(context.config),
+            list_str,
+            list_offset.block_unindent(context.config).to_string(
+                context.config,
+            )
+        )
     } else if context.config.spaces_within_angle_brackets() {
         format!("< {} >", list_str)
     } else {
@@ -2413,10 +2472,12 @@ fn rewrite_trait_bounds(
     if bounds.is_empty() {
         return Some(String::new());
     }
-    let bound_str = try_opt!(bounds
-                                 .iter()
-                                 .map(|ty_bound| ty_bound.rewrite(&context, shape))
-                                 .collect::<Option<Vec<_>>>());
+    let bound_str = try_opt!(
+        bounds
+            .iter()
+            .map(|ty_bound| ty_bound.rewrite(&context, shape))
+            .collect::<Option<Vec<_>>>()
+    );
     Some(format!(": {}", join_bounds(context, shape, &bound_str)))
 }
 
@@ -2446,14 +2507,16 @@ fn rewrite_where_clause_rfc_style(
     let len = where_clause.predicates.len();
     let end_of_preds = span_for_where_pred(&where_clause.predicates[len - 1]).hi;
     let span_end = span_end.unwrap_or(end_of_preds);
-    let items = itemize_list(context.codemap,
-                             where_clause.predicates.iter(),
-                             terminator,
-                             |pred| span_for_where_pred(pred).lo,
-                             |pred| span_for_where_pred(pred).hi,
-                             |pred| pred.rewrite(context, shape),
-                             span_start,
-                             span_end);
+    let items = itemize_list(
+        context.codemap,
+        where_clause.predicates.iter(),
+        terminator,
+        |pred| span_for_where_pred(pred).lo,
+        |pred| span_for_where_pred(pred).hi,
+        |pred| pred.rewrite(context, shape),
+        span_start,
+        span_end,
+    );
     let comma_tactic = if suppress_comma {
         SeparatorTactic::Never
     } else {
diff --git a/src/lib.rs b/src/lib.rs
index 2ede6d9a2f0..2aa477ccafa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -468,8 +468,10 @@ where
         }
         // Reset the error count.
         if parse_session.span_diagnostic.has_errors() {
-            let silent_emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()),
-                                                             Some(codemap.clone())));
+            let silent_emitter = Box::new(EmitterWriter::new(
+                Box::new(Vec::new()),
+                Some(codemap.clone()),
+            ));
             parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter);
         }
     }
diff --git a/src/lists.rs b/src/lists.rs
index 37acff692a4..24bd10e24a0 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -555,20 +555,20 @@ pub fn struct_lit_shape(
     prefix_width: usize,
     suffix_width: usize,
 ) -> Option<(Option<Shape>, Shape)> {
-    let v_shape =
-        match context.config.struct_lit_style() {
-            IndentStyle::Visual => {
-                try_opt!(try_opt!(shape.visual_indent(0).shrink_left(prefix_width))
-                         .sub_width(suffix_width))
-            }
-            IndentStyle::Block => {
-                let shape = shape.block_indent(context.config.tab_spaces());
-                Shape {
-                    width: try_opt!(context.config.max_width().checked_sub(shape.indent.width())),
-                    ..shape
-                }
+    let v_shape = match context.config.struct_lit_style() {
+        IndentStyle::Visual => {
+            try_opt!(
+                try_opt!(shape.visual_indent(0).shrink_left(prefix_width)).sub_width(suffix_width)
+            )
+        }
+        IndentStyle::Block => {
+            let shape = shape.block_indent(context.config.tab_spaces());
+            Shape {
+                width: try_opt!(context.config.max_width().checked_sub(shape.indent.width())),
+                ..shape
             }
-        };
+        }
+    };
     let h_shape = shape.sub_width(prefix_width + suffix_width);
     Some((h_shape, v_shape))
 }
diff --git a/src/patterns.rs b/src/patterns.rs
index a52f42157b8..25290ceaf0e 100644
--- a/src/patterns.rs
+++ b/src/patterns.rs
@@ -81,7 +81,8 @@ impl Rewrite for Pat {
                 rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)
             }
             PatKind::TupleStruct(ref path, ref pat_vec, dotdot_pos) => {
-                let path_str = try_opt!(rewrite_path(context, PathContext::Expr, None, path, shape));
+                let path_str =
+                    try_opt!(rewrite_path(context, PathContext::Expr, None, path, shape));
                 rewrite_tuple_pat(
                     pat_vec,
                     dotdot_pos,
diff --git a/src/string.rs b/src/string.rs
index 904260e8182..6c20c18ca47 100644
--- a/src/string.rs
+++ b/src/string.rs
@@ -42,12 +42,10 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
 
     // `cur_start` is the position in `orig` of the start of the current line.
     let mut cur_start = 0;
-    let mut result = String::with_capacity(
-        stripped_str
-            .len()
-            .checked_next_power_of_two()
-            .unwrap_or(usize::max_value()),
-    );
+    let mut result =
+        String::with_capacity(stripped_str.len().checked_next_power_of_two().unwrap_or(
+            usize::max_value(),
+        ));
     result.push_str(fmt.opener);
 
     let ender_length = fmt.line_end.len();
diff --git a/src/types.rs b/src/types.rs
index b1cea7df864..5e57ce790a7 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -226,18 +226,22 @@ fn rewrite_segment(
 
                 let generics_shape =
                     generics_shape_from_config(context.config, shape, separator.len());
-                let items = itemize_list(context.codemap,
-                                         param_list.into_iter(),
-                                         ">",
-                                         |param| param.get_span().lo,
-                                         |param| param.get_span().hi,
-                                         |seg| seg.rewrite(context, generics_shape),
-                                         list_lo,
-                                         span_hi);
-                let generics_str = try_opt!(format_generics_item_list(context,
-                                                                      items,
-                                                                      generics_shape,
-                                                                      generics_shape.width));
+                let items = itemize_list(
+                    context.codemap,
+                    param_list.into_iter(),
+                    ">",
+                    |param| param.get_span().lo,
+                    |param| param.get_span().hi,
+                    |seg| seg.rewrite(context, generics_shape),
+                    list_lo,
+                    span_hi,
+                );
+                let generics_str = try_opt!(format_generics_item_list(
+                    context,
+                    items,
+                    generics_shape,
+                    generics_shape.width,
+                ));
 
                 // Update position of last bracket.
                 *span_lo = next_span_lo;
@@ -307,9 +311,9 @@ where
         context.codemap,
         // FIXME Would be nice to avoid this allocation,
         // but I couldn't get the types to work out.
-        inputs
-            .map(|i| ArgumentKind::Regular(Box::new(i)))
-            .chain(variadic_arg),
+        inputs.map(|i| ArgumentKind::Regular(Box::new(i))).chain(
+            variadic_arg,
+        ),
         ")",
         |arg| match *arg {
             ArgumentKind::Regular(ref ty) => ty.span().lo,
@@ -387,11 +391,12 @@ impl Rewrite for ast::WherePredicate {
                     // 6 = "for<> ".len()
                     let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
                     let ty_shape = try_opt!(shape.block_left(used_width));
-                    let bounds: Vec<_> =
-                        try_opt!(bounds
-                                     .iter()
-                                     .map(|ty_bound| ty_bound.rewrite(context, ty_shape))
-                                     .collect());
+                    let bounds: Vec<_> = try_opt!(
+                        bounds
+                            .iter()
+                            .map(|ty_bound| ty_bound.rewrite(context, ty_shape))
+                            .collect()
+                    );
                     let bounds_str = join_bounds(context, ty_shape, &bounds);
 
                     if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 {
@@ -411,11 +416,12 @@ impl Rewrite for ast::WherePredicate {
                         Style::Legacy => try_opt!(shape.block_left(used_width)),
                         Style::Rfc => shape.block_indent(context.config.tab_spaces()),
                     };
-                    let bounds: Vec<_> =
-                        try_opt!(bounds
-                                     .iter()
-                                     .map(|ty_bound| ty_bound.rewrite(context, ty_shape))
-                                     .collect());
+                    let bounds: Vec<_> = try_opt!(
+                        bounds
+                            .iter()
+                            .map(|ty_bound| ty_bound.rewrite(context, ty_shape))
+                            .collect()
+                    );
                     let bounds_str = join_bounds(context, ty_shape, &bounds);
 
                     format!("{}{}{}", type_str, colon, bounds_str)
@@ -482,10 +488,12 @@ where
         );
         let colon = type_bound_colon(context);
         let overhead = last_line_width(&result) + colon.len();
-        let result = format!("{}{}{}",
-                             result,
-                             colon,
-                             join_bounds(context, try_opt!(shape.sub_width(overhead)), &appendix));
+        let result = format!(
+            "{}{}{}",
+            result,
+            colon,
+            join_bounds(context, try_opt!(shape.sub_width(overhead)), &appendix)
+        );
         wrap_str(result, context.config.max_width(), shape)
     }
 }
@@ -540,10 +548,12 @@ impl Rewrite for ast::TyParam {
         result.push_str(&self.ident.to_string());
         if !self.bounds.is_empty() {
             result.push_str(type_bound_colon(context));
-            let strs: Vec<_> = try_opt!(self.bounds
-                                            .iter()
-                                            .map(|ty_bound| ty_bound.rewrite(context, shape))
-                                            .collect());
+            let strs: Vec<_> = try_opt!(
+                self.bounds
+                    .iter()
+                    .map(|ty_bound| ty_bound.rewrite(context, shape))
+                    .collect()
+            );
             result.push_str(&join_bounds(context, shape, &strs));
         }
         if let Some(ref def) = self.default {