Skip to content

Commit 8e5c760

Browse files
committed
Implement ptr_vec_to_ref_vec()
1 parent 7e309a4 commit 8e5c760

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/expr.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use string::{rewrite_string, StringFormat};
3333
use types::{can_be_overflowed_type, rewrite_path, PathContext};
3434
use utils::{binary_search, colon_spaces, contains_skip, extra_offset, first_line_width,
3535
inner_attributes, last_line_extendable, last_line_width, left_most_sub_expr, mk_sp,
36-
outer_attributes, paren_overhead, semicolon_for_stmt, stmt_expr,
36+
outer_attributes, paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr,
3737
trimmed_last_line_width, wrap_str};
3838
use vertical::rewrite_with_alignment;
3939
use visitor::FmtVisitor;
@@ -85,7 +85,7 @@ pub fn format_expr(
8585
rewrite_call_with_binary_search(
8686
context,
8787
&**callee,
88-
&args.iter().map(|x| &**x).collect::<Vec<_>>()[..],
88+
&ptr_vec_to_ref_vec(&args),
8989
inner_span,
9090
shape,
9191
)
@@ -112,12 +112,9 @@ pub fn format_expr(
112112
expr.span,
113113
shape,
114114
),
115-
ast::ExprKind::Tup(ref items) => rewrite_tuple(
116-
context,
117-
&items.iter().map(|x| &**x).collect::<Vec<_>>()[..],
118-
expr.span,
119-
shape,
120-
),
115+
ast::ExprKind::Tup(ref items) => {
116+
rewrite_tuple(context, &ptr_vec_to_ref_vec(&items), expr.span, shape)
117+
}
121118
ast::ExprKind::If(..) |
122119
ast::ExprKind::IfLet(..) |
123120
ast::ExprKind::ForLoop(..) |
@@ -2037,7 +2034,7 @@ pub fn rewrite_call(
20372034
rewrite_call_inner(
20382035
context,
20392036
callee,
2040-
&args.iter().map(|x| &**x).collect::<Vec<_>>(),
2037+
&ptr_vec_to_ref_vec(&args),
20412038
span,
20422039
shape,
20432040
context.config.fn_call_width(),

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl Rewrite for ast::Ty {
727727
}
728728
ast::TyKind::Tup(ref items) => rewrite_tuple(
729729
context,
730-
&items.iter().map(|x| &**x).collect::<Vec<_>>()[..],
730+
&::utils::ptr_vec_to_ref_vec(&items),
731731
self.span,
732732
shape,
733733
),

src/utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::borrow::Cow;
1212
use std::cmp::Ordering;
1313

14-
use syntax::abi;
14+
use syntax::{abi, ptr};
1515
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind,
1616
Path, Visibility};
1717
use syntax::codemap::{BytePos, Span, NO_EXPANSION};
@@ -97,6 +97,12 @@ pub fn format_abi(abi: abi::Abi, explicit_abi: bool) -> String {
9797
}
9898
}
9999

100+
#[inline]
101+
// Transform `Vec<syntax::ptr::P<T>>` into `Vec<&T>`
102+
pub fn ptr_vec_to_ref_vec<T>(vec: &[ptr::P<T>]) -> Vec<&T> {
103+
vec.iter().map(|x| &**x).collect::<Vec<_>>()
104+
}
105+
100106
#[inline]
101107
pub fn filter_attributes(attrs: &[ast::Attribute], style: ast::AttrStyle) -> Vec<ast::Attribute> {
102108
attrs

0 commit comments

Comments
 (0)