Skip to content

Disallow combining parens and brackets in impl #2518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use types::join_bounds;
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
format_defaultness, format_mutability, format_unsafety, format_visibility,
is_attributes_extendable, last_line_contains_single_line_comment,
last_line_extendable, last_line_used_width, last_line_width, mk_sp,
semicolon_for_expr, starts_with_newline, stmt_expr, trimmed_last_line_width};
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
stmt_expr, trimmed_last_line_width};
use vertical::rewrite_with_alignment;
use visitor::FmtVisitor;

Expand Down Expand Up @@ -631,8 +631,7 @@ pub fn format_impl(
}
result.push_str(&where_clause_str);

let need_newline = !last_line_extendable(&result)
&& (last_line_contains_single_line_comment(&result) || result.contains('\n'));
let need_newline = last_line_contains_single_line_comment(&result) || result.contains('\n');
match context.config.brace_style() {
_ if need_newline => result.push_str(&sep),
BraceStyle::AlwaysNextLine => result.push_str(&sep),
Expand Down
5 changes: 5 additions & 0 deletions tests/source/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,8 @@ impl Foo {
1
}
}

// #2491
impl<'a, 'b, 'c> SomeThing<Something> for (&'a mut SomethingLong, &'b mut SomethingLong, &'c mut SomethingLong) {
fn foo() {}
}
9 changes: 6 additions & 3 deletions tests/target/big-impl-block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyL
ExcessivelyLongGenericName,
ExcessivelyLongGenericName,
AnotherExcessivelyLongGenericName,
> {
>
{
fn foo() {}
}
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
for Bar<
ExcessivelyLongGenericName,
ExcessivelyLongGenericName,
AnotherExcessivelyLongGenericName,
> {
>
{
fn foo() {}
}
impl<
Expand All @@ -72,7 +74,8 @@ impl<
ExcessivelyLongGenericName,
ExcessivelyLongGenericName,
AnotherExcessivelyLongGenericName,
> {
>
{
fn foo() {}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/target/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,14 @@ impl Foo {
1
}
}

// #2491
impl<'a, 'b, 'c> SomeThing<Something>
for (
&'a mut SomethingLong,
&'b mut SomethingLong,
&'c mut SomethingLong,
)
{
fn foo() {}
}