mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Merge pull request #1654 from topecongiro/over-long-lines
Use block indent for args of macro if single line args exceeds max width
This commit is contained in:
commit
6ed3077651
32
src/expr.rs
32
src/expr.rs
@ -1721,6 +1721,20 @@ fn rewrite_call_inner(context: &RewriteContext,
|
||||
nested_shape,
|
||||
one_line_width,
|
||||
force_trailing_comma)
|
||||
.or_else(|| if context.use_block_indent() {
|
||||
rewrite_call_args(context,
|
||||
args,
|
||||
args_span,
|
||||
Shape::indented(shape
|
||||
.block()
|
||||
.indent
|
||||
.block_indent(context.config),
|
||||
context.config),
|
||||
0,
|
||||
force_trailing_comma)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.ok_or(Ordering::Less)?;
|
||||
|
||||
if !context.use_block_indent() && need_block_indent(&list_str, nested_shape) && !extendable {
|
||||
@ -1734,9 +1748,12 @@ fn rewrite_call_inner(context: &RewriteContext,
|
||||
force_trailing_comma);
|
||||
}
|
||||
|
||||
let args_shape = shape
|
||||
.sub_width(last_line_width(&callee_str))
|
||||
.ok_or(Ordering::Less)?;
|
||||
Ok(format!("{}{}",
|
||||
callee_str,
|
||||
wrap_args_with_parens(context, &list_str, extendable, shape, nested_shape)))
|
||||
wrap_args_with_parens(context, &list_str, extendable, args_shape, nested_shape)))
|
||||
}
|
||||
|
||||
fn need_block_indent(s: &str, shape: Shape) -> bool {
|
||||
@ -1906,14 +1923,23 @@ fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_len:
|
||||
}
|
||||
}
|
||||
|
||||
fn paren_overhead(context: &RewriteContext) -> usize {
|
||||
if context.config.spaces_within_parens() {
|
||||
4
|
||||
} else {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_args_with_parens(context: &RewriteContext,
|
||||
args_str: &str,
|
||||
is_extendable: bool,
|
||||
shape: Shape,
|
||||
nested_shape: Shape)
|
||||
-> String {
|
||||
if !context.use_block_indent() || (context.inside_macro && !args_str.contains('\n')) ||
|
||||
is_extendable {
|
||||
if !context.use_block_indent() ||
|
||||
(context.inside_macro && !args_str.contains('\n') &&
|
||||
args_str.len() + paren_overhead(context) <= shape.width) || is_extendable {
|
||||
if context.config.spaces_within_parens() && args_str.len() > 0 {
|
||||
format!("( {} )", args_str)
|
||||
} else {
|
||||
|
@ -125,3 +125,9 @@ fn issue1581() {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn issue1651() {
|
||||
{
|
||||
let type_list: Vec<_> = try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect());
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
|
||||
// rustfmt should not add trailing comma when rewriting macro. See #1528.
|
||||
fn a() {
|
||||
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
|
||||
panic!(
|
||||
"this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"
|
||||
);
|
||||
foo(
|
||||
oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt(),
|
||||
);
|
||||
|
@ -145,3 +145,10 @@ fn issue1581() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn issue1651() {
|
||||
{
|
||||
let type_list: Vec<_> =
|
||||
try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user