diff --git a/src/types.rs b/src/types.rs index 80ff8ce498a..676095ff4ce 100644 --- a/src/types.rs +++ b/src/types.rs @@ -18,8 +18,8 @@ use codemap::SpanUtils; use config::{IndentStyle, TypeDensity}; -use expr::{rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix, - PairParts, ToExpr}; +use expr::{rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix, PairParts, + ToExpr}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; use macros::{rewrite_macro, MacroPosition}; use overflow; @@ -485,17 +485,13 @@ fn rewrite_bounded_lifetime( if bounds.len() == 0 { Some(result) } else { - let appendix = bounds - .iter() - .map(|b| b.rewrite(context, shape)) - .collect::>>()?; let colon = type_bound_colon(context); let overhead = last_line_width(&result) + colon.len(); let result = format!( "{}{}{}", result, colon, - join_bounds(context, shape.sub_width(overhead)?, bounds, &appendix, true)? + join_bounds(context, shape.sub_width(overhead)?, bounds, true)? ); Some(result) } @@ -529,20 +525,13 @@ pub struct TraitTyParamBounds<'a> { impl<'a> Rewrite for TraitTyParamBounds<'a> { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { - let strs = self.inner - .iter() - .map(|b| b.rewrite(context, shape)) - .collect::>>()?; - join_bounds(context, shape, self.inner, &strs, false) + join_bounds(context, shape, self.inner, false) } } impl Rewrite for ast::TyParamBounds { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { - let strs = self.iter() - .map(|b| b.rewrite(context, shape)) - .collect::>>()?; - join_bounds(context, shape, self, &strs, true) + join_bounds(context, shape, self, true) } } @@ -779,7 +768,6 @@ fn join_bounds( context: &RewriteContext, shape: Shape, items: &[T], - type_strs: &[String], need_indent: bool, ) -> Option where @@ -790,6 +778,10 @@ fn join_bounds( TypeDensity::Compressed => "+", TypeDensity::Wide => " + ", }; + let type_strs = items + .iter() + .map(|item| item.rewrite(context, shape)) + .collect::>>()?; let result = type_strs.join(joiner); if items.len() == 1 || (!result.contains('\n') && result.len() <= shape.width) { return Some(result); @@ -805,7 +797,7 @@ fn join_bounds( .collect::>>()?; (type_strs, nested_shape.indent) } else { - (type_strs.to_vec(), shape.indent) + (type_strs, shape.indent) }; let joiner = format!("{}+ ", offset.to_string_with_newline(context.config)); diff --git a/tests/target/trait.rs b/tests/target/trait.rs index fa54b1d2df1..d1ee43f4e3f 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -65,8 +65,7 @@ trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt { } -trait FooBar: - Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +trait FooBar: Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt where J: Bar, {