Skip to content

Trait Implementation - Adds a newline before the last brace on impls without a body if the first brace is also on a newline #3050

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

Conversation

andrehjr
Copy link
Contributor

Hi there, this is my first PR :) Let me know if there's a better way to fix this.

This PRs ends up bypassing the 'empty_item_single_line' configuration when the { is on a new line. (related to #2771).

According to the comments from #3046, this is the expected behavior. Fixes #3046

@andrehjr andrehjr force-pushed the empty-impl-body-with-braces-newline branch from 849ebf4 to 0d6f2ad Compare September 25, 2018 13:12
src/items.rs Outdated
@@ -757,9 +757,12 @@ pub fn format_impl(
result.push_str(&outer_indent_str);
}

if result.ends_with('{') && !context.config.empty_item_single_line() {
if result.ends_with('{')
&& (!context.config.empty_item_single_line() || trimmed_last_line_width(&result) == 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can reuse the variable need_newline https://github.com/rust-lang-nursery/rustfmt/pull/3050/files#diff-5db152a52bdaeae9dacd35f43a4a78ddR722 which is true if a newline before { was needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip! True. It's possible to reuse need_newline here, and that made the code much simpler.

Adds a newline before the last brace on impls without a body if the first brace is also on a newline
@andrehjr andrehjr force-pushed the empty-impl-body-with-braces-newline branch from 0d6f2ad to 2727d41 Compare September 26, 2018 12:44
@topecongiro
Copy link
Contributor

Thanks!

@topecongiro topecongiro merged commit 86fff9e into rust-lang:master Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trait implementation and trait declaration with no body and many bounds have inconsistent bracing style
3 participants