Skip to content

Commit b12fecb

Browse files
committed
Use horizontal layout for a function with a single argument
foo(long_arg) instead of foo( long_arg, )
1 parent b751030 commit b12fecb

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/expr.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,12 +2215,23 @@ where
22152215
_ if args.len() >= 1 => {
22162216
item_vec[args.len() - 1].item = args.last()
22172217
.and_then(|last_arg| last_arg.rewrite(context, shape));
2218-
tactic = definitive_tactic(
2219-
&*item_vec,
2220-
ListTactic::LimitedHorizontalVertical(args_max_width),
2221-
Separator::Comma,
2222-
one_line_width,
2223-
);
2218+
// Use horizontal layout for a function with a single argument as long as
2219+
// everything fits in a single line.
2220+
if args.len() == 1
2221+
&& args_max_width != 0 // Vertical layout is forced.
2222+
&& !item_vec[0].has_comment()
2223+
&& !item_vec[0].inner_as_ref().contains('\n')
2224+
&& ::lists::total_item_width(&item_vec[0]) <= one_line_width
2225+
{
2226+
tactic = DefinitiveListTactic::Horizontal;
2227+
} else {
2228+
tactic = definitive_tactic(
2229+
&*item_vec,
2230+
ListTactic::LimitedHorizontalVertical(args_max_width),
2231+
Separator::Comma,
2232+
one_line_width,
2233+
);
2234+
}
22242235
}
22252236
_ => (),
22262237
}

src/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ where
713713
.fold((0, 0), |acc, l| (acc.0 + 1, acc.1 + l))
714714
}
715715

716-
fn total_item_width(item: &ListItem) -> usize {
716+
pub fn total_item_width(item: &ListItem) -> usize {
717717
comment_len(item.pre_comment.as_ref().map(|x| &(*x)[..]))
718718
+ comment_len(item.post_comment.as_ref().map(|x| &(*x)[..]))
719719
+ item.item.as_ref().map_or(0, |str| str.len())

0 commit comments

Comments
 (0)