Skip to content
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

Comments on lines with curlies are moved to the next line. #3527

Closed
DanielSchuette opened this issue Apr 25, 2019 · 4 comments
Closed

Comments on lines with curlies are moved to the next line. #3527

DanielSchuette opened this issue Apr 25, 2019 · 4 comments

Comments

@DanielSchuette
Copy link

DanielSchuette commented Apr 25, 2019

I don't know if this was already reported, but I observe the following behavior:

If I have comments on the same line as opening or closing curly braces (nothing one usually does, I know), the code gets reformatted as follows.

// ...
} else { /* some comment, either this style or '//' */
// ...

becomes:

// ...
} else {
/* the comment ends up on the next line! */
// ...

My use-case is running code through a post-processor that needs comments to be on a line with the braces, so I would really, really appreciate an option to turn this behavior off. Thanks for considering this request!

@nokola
Copy link

nokola commented Dec 17, 2019

Another use case: in our team we usually "explain if-s" with the intention of the if statement like so:

if self.root == None { // if empty tree

As is, rustfmt will convert the above code to:

if self.root == None {
    // if empty tree

Which is undesired. Would love to have an option to keep comments on the same line.

@calebcartwright
Copy link
Member

calebcartwright commented Dec 17, 2019

@nokola what version of rustfmt are you using? with the latest version of rustfmt on master the comments are now left on the same line in both your snippet and the snippet from @DanielSchuette in the OP.

I forget exactly which version of rustfmt would contain the fix as there have been quite a few comment-related PRs over the last several weeks

Oops! I was using the litteral snippets above and the same-line comments are not moved on empty blocks. This is still reproducible with non-emtpy blocks, though I believe this is a duplicate of #3255

@topecongiro
Copy link
Contributor

Closing in favor of #3255.

@nokola
Copy link

nokola commented Jan 15, 2020

Yes, the scenario I reported is duplicate of #3255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants