commit
d476bef7ed
5 changed files with 69 additions and 11 deletions
|
@ -441,5 +441,5 @@ fn rewrite_method_call(method_name: ast::Ident,
|
|||
let callee_str = format!(".{}{}", method_name, type_str);
|
||||
let span = mk_sp(lo, span.hi);
|
||||
|
||||
rewrite_call(context, &callee_str, &args[1..], span, shape)
|
||||
rewrite_call(context, &callee_str, &args[1..], span, shape, false)
|
||||
}
|
||||
|
|
27
src/expr.rs
27
src/expr.rs
|
@ -71,7 +71,7 @@ fn format_expr(expr: &ast::Expr,
|
|||
}
|
||||
ast::ExprKind::Call(ref callee, ref args) => {
|
||||
let inner_span = mk_sp(callee.span.hi, expr.span.hi);
|
||||
rewrite_call(context, &**callee, args, inner_span, shape)
|
||||
rewrite_call(context, &**callee, args, inner_span, shape, false)
|
||||
}
|
||||
ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape),
|
||||
ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => {
|
||||
|
@ -1597,12 +1597,20 @@ pub fn rewrite_call<R>(context: &RewriteContext,
|
|||
callee: &R,
|
||||
args: &[ptr::P<ast::Expr>],
|
||||
span: Span,
|
||||
shape: Shape)
|
||||
shape: Shape,
|
||||
force_no_trailing_comma: bool)
|
||||
-> Option<String>
|
||||
where R: Rewrite
|
||||
{
|
||||
let closure =
|
||||
|callee_max_width| rewrite_call_inner(context, callee, callee_max_width, args, span, shape);
|
||||
let closure = |callee_max_width| {
|
||||
rewrite_call_inner(context,
|
||||
callee,
|
||||
callee_max_width,
|
||||
args,
|
||||
span,
|
||||
shape,
|
||||
force_no_trailing_comma)
|
||||
};
|
||||
|
||||
// 2 is for parens
|
||||
let max_width = try_opt!(shape.width.checked_sub(2));
|
||||
|
@ -1614,7 +1622,8 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|
|||
max_callee_width: usize,
|
||||
args: &[ptr::P<ast::Expr>],
|
||||
span: Span,
|
||||
shape: Shape)
|
||||
shape: Shape,
|
||||
force_no_trailing_comma: bool)
|
||||
-> Result<String, Ordering>
|
||||
where R: Rewrite
|
||||
{
|
||||
|
@ -1721,9 +1730,11 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|
|||
let fmt = ListFormatting {
|
||||
tactic: tactic,
|
||||
separator: ",",
|
||||
trailing_separator: match context.config.fn_call_style {
|
||||
IndentStyle::Visual => SeparatorTactic::Never,
|
||||
IndentStyle::Block => context.config.trailing_comma,
|
||||
trailing_separator: if force_no_trailing_comma ||
|
||||
context.config.fn_call_style == IndentStyle::Visual {
|
||||
SeparatorTactic::Never
|
||||
} else {
|
||||
context.config.trailing_comma
|
||||
},
|
||||
shape: nested_shape,
|
||||
ends_with_newline: false,
|
||||
|
|
|
@ -144,8 +144,9 @@ pub fn rewrite_macro(mac: &ast::Mac,
|
|||
|
||||
match style {
|
||||
MacroStyle::Parens => {
|
||||
// Format macro invocation as function call.
|
||||
rewrite_call(context, ¯o_name, &expr_vec, mac.span, shape).map(|rw| {
|
||||
// Format macro invocation as function call, forcing no trailing
|
||||
// comma because not all macros support them.
|
||||
rewrite_call(context, ¯o_name, &expr_vec, mac.span, shape, true).map(|rw| {
|
||||
match position {
|
||||
MacroPosition::Item => format!("{};", rw),
|
||||
_ => rw,
|
||||
|
|
|
@ -109,3 +109,14 @@ fn function_calls() {
|
|||
span.lo,
|
||||
span.hi)
|
||||
}
|
||||
|
||||
fn macros() {
|
||||
baz!(do_not, add, trailing, commas, inside, of, function, like, macros, even, if_they, are, long);
|
||||
|
||||
baz!(one_item_macro_which_is_also_loooooooooooooooooooooooooooooooooooooooooooooooong);
|
||||
|
||||
let _ = match option {
|
||||
None => baz!(function, like, macro_as, expression, which, is, loooooooooooooooong),
|
||||
Some(p) => baz!(one_item_macro_as_expression_which_is_also_loooooooooooooooong),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -149,3 +149,38 @@ fn function_calls() {
|
|||
span.hi,
|
||||
)
|
||||
}
|
||||
|
||||
fn macros() {
|
||||
baz!(
|
||||
do_not,
|
||||
add,
|
||||
trailing,
|
||||
commas,
|
||||
inside,
|
||||
of,
|
||||
function,
|
||||
like,
|
||||
macros,
|
||||
even,
|
||||
if_they,
|
||||
are,
|
||||
long
|
||||
);
|
||||
|
||||
baz!(one_item_macro_which_is_also_loooooooooooooooooooooooooooooooooooooooooooooooong);
|
||||
|
||||
let _ = match option {
|
||||
None => {
|
||||
baz!(
|
||||
function,
|
||||
like,
|
||||
macro_as,
|
||||
expression,
|
||||
which,
|
||||
is,
|
||||
loooooooooooooooong
|
||||
)
|
||||
}
|
||||
Some(p) => baz!(one_item_macro_as_expression_which_is_also_loooooooooooooooong),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue