diff --git a/src/expr.rs b/src/expr.rs index 0b9511e02ce..7d3a9453388 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -33,7 +33,7 @@ use string::{rewrite_string, StringFormat}; use types::{can_be_overflowed_type, rewrite_path, PathContext}; use utils::{binary_search, colon_spaces, contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, last_line_width, left_most_sub_expr, mk_sp, - outer_attributes, paren_overhead, semicolon_for_stmt, stmt_expr, + outer_attributes, paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr, trimmed_last_line_width, wrap_str}; use vertical::rewrite_with_alignment; use visitor::FmtVisitor; @@ -85,7 +85,7 @@ pub fn format_expr( rewrite_call_with_binary_search( context, &**callee, - &args.iter().map(|x| &**x).collect::>()[..], + &ptr_vec_to_ref_vec(&args), inner_span, shape, ) @@ -112,12 +112,9 @@ pub fn format_expr( expr.span, shape, ), - ast::ExprKind::Tup(ref items) => rewrite_tuple( - context, - &items.iter().map(|x| &**x).collect::>()[..], - expr.span, - shape, - ), + ast::ExprKind::Tup(ref items) => { + rewrite_tuple(context, &ptr_vec_to_ref_vec(&items), expr.span, shape) + } ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) | ast::ExprKind::ForLoop(..) | @@ -2037,7 +2034,7 @@ pub fn rewrite_call( rewrite_call_inner( context, callee, - &args.iter().map(|x| &**x).collect::>(), + &ptr_vec_to_ref_vec(&args), span, shape, context.config.fn_call_width(), diff --git a/src/types.rs b/src/types.rs index ceca0417aa8..057acdcb0f1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -727,7 +727,7 @@ impl Rewrite for ast::Ty { } ast::TyKind::Tup(ref items) => rewrite_tuple( context, - &items.iter().map(|x| &**x).collect::>()[..], + &::utils::ptr_vec_to_ref_vec(&items), self.span, shape, ), diff --git a/src/utils.rs b/src/utils.rs index 438bb027637..6ec90fab59a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,7 @@ use std::borrow::Cow; use std::cmp::Ordering; -use syntax::abi; +use syntax::{abi, ptr}; use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path, Visibility}; use syntax::codemap::{BytePos, Span, NO_EXPANSION}; @@ -97,6 +97,12 @@ pub fn format_abi(abi: abi::Abi, explicit_abi: bool) -> String { } } +#[inline] +// Transform `Vec>` into `Vec<&T>` +pub fn ptr_vec_to_ref_vec(vec: &[ptr::P]) -> Vec<&T> { + vec.iter().map(|x| &**x).collect::>() +} + #[inline] pub fn filter_attributes(attrs: &[ast::Attribute], style: ast::AttrStyle) -> Vec { attrs