mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Line breaking around generics in tuple structs
This commit is contained in:
parent
d5478f7d45
commit
4df405a768
65
src/items.rs
65
src/items.rs
@ -1018,19 +1018,16 @@ fn format_tuple_struct(context: &RewriteContext,
|
|||||||
|
|
||||||
let (tactic, item_indent) = match context.config.fn_args_layout {
|
let (tactic, item_indent) = match context.config.fn_args_layout {
|
||||||
FnArgLayoutStyle::Visual => {
|
FnArgLayoutStyle::Visual => {
|
||||||
result.push('(');
|
// 1 = `(`
|
||||||
(ListTactic::HorizontalVertical, offset.block_only() + result.len())
|
(ListTactic::HorizontalVertical, offset.block_only() + result.len() + 1)
|
||||||
}
|
}
|
||||||
FnArgLayoutStyle::Block |
|
FnArgLayoutStyle::Block |
|
||||||
FnArgLayoutStyle::BlockAlways => {
|
FnArgLayoutStyle::BlockAlways => {
|
||||||
let indent = offset.block_only().block_indent(&context.config);
|
(ListTactic::HorizontalVertical, offset.block_only().block_indent(&context.config))
|
||||||
result.push_str("(\n");
|
|
||||||
result.push_str(&indent.to_string(&context.config));
|
|
||||||
(ListTactic::Vertical, indent)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 2 = ");"
|
// 3 = `();`
|
||||||
let item_budget = try_opt!(context.config.max_width.checked_sub(item_indent.width() + 2));
|
let item_budget = try_opt!(context.config.max_width.checked_sub(item_indent.width() + 3));
|
||||||
|
|
||||||
let items =
|
let items =
|
||||||
itemize_list(context.codemap,
|
itemize_list(context.codemap,
|
||||||
@ -1048,31 +1045,34 @@ fn format_tuple_struct(context: &RewriteContext,
|
|||||||
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
|
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
|
||||||
context.codemap.span_after(span, "("),
|
context.codemap.span_after(span, "("),
|
||||||
span.hi);
|
span.hi);
|
||||||
|
let body_budget = try_opt!(context.config.max_width.checked_sub(offset.block_only().width() +
|
||||||
|
result.len() +
|
||||||
|
3));
|
||||||
let body = try_opt!(list_helper(items,
|
let body = try_opt!(list_helper(items,
|
||||||
Shape::legacy(item_budget, item_indent),
|
// TODO budget is wrong in block case
|
||||||
|
Shape::legacy(body_budget, item_indent),
|
||||||
context.config,
|
context.config,
|
||||||
tactic));
|
tactic));
|
||||||
|
|
||||||
if context.config.spaces_within_parens && body.len() > 0 {
|
if context.config.fn_args_layout == FnArgLayoutStyle::Visual || !body.contains('\n') {
|
||||||
result.push(' ');
|
result.push('(');
|
||||||
}
|
if context.config.spaces_within_parens && body.len() > 0 {
|
||||||
|
result.push(' ');
|
||||||
result.push_str(&body);
|
|
||||||
|
|
||||||
if context.config.spaces_within_parens && body.len() > 0 {
|
|
||||||
result.push(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
match context.config.fn_args_layout {
|
|
||||||
FnArgLayoutStyle::Visual => {
|
|
||||||
result.push(')');
|
|
||||||
}
|
}
|
||||||
FnArgLayoutStyle::Block |
|
|
||||||
FnArgLayoutStyle::BlockAlways => {
|
result.push_str(&body);
|
||||||
result.push('\n');
|
|
||||||
result.push_str(&offset.block_only().to_string(&context.config));
|
if context.config.spaces_within_parens && body.len() > 0 {
|
||||||
result.push(')');
|
result.push(' ');
|
||||||
}
|
}
|
||||||
|
result.push(')');
|
||||||
|
} else {
|
||||||
|
result.push_str("(\n");
|
||||||
|
result.push_str(&item_indent.to_string(&context.config));
|
||||||
|
result.push_str(&body);
|
||||||
|
result.push('\n');
|
||||||
|
result.push_str(&offset.block_only().to_string(&context.config));
|
||||||
|
result.push(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
if !where_clause_str.is_empty() && !where_clause_str.contains('\n') &&
|
if !where_clause_str.is_empty() && !where_clause_str.contains('\n') &&
|
||||||
@ -1563,12 +1563,11 @@ fn rewrite_fn_base(context: &RewriteContext,
|
|||||||
|
|
||||||
let multi_line_arg_str = arg_str.contains('\n');
|
let multi_line_arg_str = arg_str.contains('\n');
|
||||||
|
|
||||||
let put_args_in_block = (match context.config.fn_args_layout {
|
let put_args_in_block = match context.config.fn_args_layout {
|
||||||
FnArgLayoutStyle::Block => multi_line_arg_str,
|
FnArgLayoutStyle::Block => multi_line_arg_str || generics_str.contains('\n'),
|
||||||
FnArgLayoutStyle::BlockAlways => true,
|
FnArgLayoutStyle::BlockAlways => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
} || generics_str.contains('\n')) &&
|
} && !fd.inputs.is_empty();
|
||||||
!fd.inputs.is_empty();
|
|
||||||
|
|
||||||
if put_args_in_block {
|
if put_args_in_block {
|
||||||
arg_indent = indent.block_indent(context.config);
|
arg_indent = indent.block_indent(context.config);
|
||||||
|
@ -12,10 +12,11 @@ e: Eeeeeeeeeeeeeeeeeee) {
|
|||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
fn bar<
|
||||||
|
'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
TTTTTTTTTTTTT,
|
TTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW>
|
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
(a: Aaaaaaaaaaaaaaa) {
|
>(a: Aaaaaaaaaaaaaaa) {
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +43,11 @@ impl Foo {
|
|||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
fn bar<
|
||||||
|
'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
TTTTTTTTTTTTT,
|
TTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW>
|
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
|
>
|
||||||
(a: Aaaaaaaaaaaaaaa) {
|
(a: Aaaaaaaaaaaaaaa) {
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
@ -56,10 +59,11 @@ impl Foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo<TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
|
struct Foo<
|
||||||
|
TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUUUU,
|
UUUUUUUUUUUUUUUUUUUUUU,
|
||||||
VVVVVVVVVVVVVVVVVVVVVVVVVVV,
|
VVVVVVVVVVVVVVVVVVVVVVVVVVV,
|
||||||
WWWWWWWWWWWWWWWWWWWWWWWW>
|
WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
{
|
> {
|
||||||
foo: Foo,
|
foo: Foo,
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,11 @@ fn foo(a: Aaaaaaaaaaaaaaa,
|
|||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
fn bar<
|
||||||
|
'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
TTTTTTTTTTTTT,
|
TTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW>
|
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
(a: Aaaaaaaaaaaaaaa) {
|
>(a: Aaaaaaaaaaaaaaa) {
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,18 +44,21 @@ impl Foo {
|
|||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
fn bar<
|
||||||
|
'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
TTTTTTTTTTTTT,
|
TTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW>
|
UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
|
>
|
||||||
(a: Aaaaaaaaaaaaaaa) {
|
(a: Aaaaaaaaaaaaaaa) {
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo<TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
|
struct Foo<
|
||||||
|
TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
|
||||||
UUUUUUUUUUUUUUUUUUUUUU,
|
UUUUUUUUUUUUUUUUUUUUUU,
|
||||||
VVVVVVVVVVVVVVVVVVVVVVVVVVV,
|
VVVVVVVVVVVVVVVVVVVVVVVVVVV,
|
||||||
WWWWWWWWWWWWWWWWWWWWWWWW>
|
WWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
{
|
> {
|
||||||
foo: Foo,
|
foo: Foo,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user