Skip to content

BraceStyle AlwaysNewLine for unsafe blocks #4422

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

IceTDrinker
Copy link
Contributor

  • Unsafe blocks can now get an opening brace on a new line

  • Add test case for unsafe blocks

Hello relating to this issue : #3376 and this issue : #3377

All comments or suggestions are very welcome, I'm far from being a rust pro :)

Cheers

@calebcartwright
Copy link
Member

Yikes! You've found a bug we've had in source for months where empty unsafe blocks get ruined 😬

* Unsafe blocks can now get an opening brace on a new line

* Add test case for unsafe blocks
@IceTDrinker IceTDrinker changed the title Control brace style AlwaysNewLine for unsafe blocks BraceStyle AlwaysNewLine for unsafe blocks Sep 15, 2020
@IceTDrinker IceTDrinker force-pushed the unsafe_block_control_brace_style branch from 798a007 to 827080a Compare September 15, 2020 17:55
@IceTDrinker
Copy link
Contributor Author

I force pushed on my branch, don't know if this is how you prefer to handle amends... sorry about that :/

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

Historically, brace_style configuration option only applied to braces of items (e.g., function, struct, enum, impl...). I don't remember that if this is intentional or we just forgot to implement it, but either way I think the PR's approach is more natural.

@IceTDrinker
Copy link
Contributor Author

Hey,

Thanks for your time and the review :)

The brace_style and control_brace_style are marked as unstable, is there a place listing what's missing to make it available in stable rustfmt ?

Cheers

@calebcartwright
Copy link
Member

@IceTDrinker

I force pushed on my branch, don't know if this is how you prefer to handle amends... sorry about that :/

No worries! We don't strictly enforce or require anything so it doesn't matter all that much. As far as personal preference, I find it easier to review updates when the changes are provided in a separate commit. We can always squash things up as needed before a merge too.

Thanks for your time and the review :)

Absolutely, and thanks for the PR!

The brace_style and control_brace_style are marked as unstable, is there a place listing what's missing to make it available in stable rustfmt ?

The requirements and process for stabilizing a rustfmt config option can be found here. I'd imagine both of those options are relative close (though haven't crawled through the issue tracker to see if there's any open bugs yet), though the need for this PR is evidence some things may still be missing for at least brace_style 😄

@calebcartwright
Copy link
Member

Historically, brace_style configuration option only applied to braces of items (e.g., function, struct, enum, impl...). I don't remember that if this is intentional or we just forgot to implement it, but either way I think the PR's approach is more natural.

And accordingly a SameLineWhere doesn't have much meaning for an unsafe block, but I definitely agree, if someone sets brace_style to AlwaysNextLine it's a very natural and reasonable assumption that the braces for unsafe (and extern for that matter) blocks would follow the next line style.

I'm going to go ahead and merge this as it's in good order and solves the issue, and will open a couple issues for the related follow ups (including updating the Config docs). Let us know if you're interested in working on those or any other issues @IceTDrinker!

@calebcartwright calebcartwright merged commit 4a88598 into rust-lang:master Sep 17, 2020
@IceTDrinker
Copy link
Contributor Author

Let us know if you're interested in working on those or any other issues @IceTDrinker!

@calebcartwright absolutely interested in helping making those features stable :) and for other things the different Rust projects might need

@calebcartwright
Copy link
Member

@calebcartwright absolutely interested in helping making those features stable :) and for other things the different Rust projects might need

Fantastic! #4428 would be a good option on both fronts, as it also ties into brace_style

@IceTDrinker IceTDrinker deleted the unsafe_block_control_brace_style branch September 19, 2020 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants