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

Format attributes on block expressions #2075

Conversation

matthew-mcallister
Copy link
Contributor

Addresses #2073, also catching extra corner cases like empty blocks. Basically the fix was to pass attributes around and reuse the existing rewriting machinery.

It would be kind of nice to put single outer attributes on the same line as the thing they modify, like

let blah = #[attr] {
    // ...
}

However, it might have to account for doc comments, and I didn't play around with it. Plus this is already a very niche case except for doing fine-grained #[rustfmt_skip], so probably no one will ever care.

@topecongiro
Copy link
Contributor

Thank you for the PR! I have created a PR against rustc which adds a field for inner attributes to ast::Block (rust-lang/rust#45426). I am not sure if it will get merged, but if it does, we will be able to handle this more concisely, rather than passing attrs: Option<&[ast::Attribute]> around.

We can merge this PR now, and update after if rust-lang/rust#45426 gets merged. Alternatively, we can wait and see if rust-lang/rust#45426 gets merged, then update this PR. I would prefer to go for the latter, as I think we are not in a hurry to merge this. How does that sound to you?

@matthew-mcallister
Copy link
Contributor Author

Oh, that sounds much nicer than what I've done here. I agree, this can wait to be merged if it means saving on the spaghetti code.

@matthew-mcallister
Copy link
Contributor Author

Now that rust-lang/rust#45426 is closed, does it sound better to merge this as-is or wait for a follow-up to the discussion there w.r.t. separating inner and outer attributes on blocks? The only downside I see is that you currently can't put #![rustfmt_skip] inside of a block expression, so I think it will be fine to defer merging for some time.

@nrc
Copy link
Member

nrc commented Nov 2, 2017

I think that depends when/if @topecongiro intends to work on the new Rust PR. If that is happening soon, then I'd wait, otherwise we can land this PR in the meantime.

@topecongiro
Copy link
Contributor

I am not going to work on the new rust PR anytime soon, so I am fine to merge this.

@topecongiro
Copy link
Contributor

Merged this in 0dca70f.

@matthew-mcallister Thank you for your work! And sorry that it took so long to merge this.

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.

3 participants