-
Notifications
You must be signed in to change notification settings - Fork 13.6k
add rustfmt support for cfg_select
#144323
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
base: master
Are you sure you want to change the base?
add rustfmt support for cfg_select
#144323
Conversation
Failed to set assignee to
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
@ytmimi seems like I can't officially make you a reviewer, so we'll have to figure out how to merge this: I can |
Maybe you can't officially assign me, but I should definitely have the ability to |
I think we might want to hold off on merging this for a tad longer. The style team has been discussing possible formatting prescriptions for the macro in our weekly meetings and while we're getting closer there's still a few things we're trying to iron out - rust-lang/style-team#201 My preference would be to give that another week or two to hopefully avoid double code churn |
I think the proposed formatting looks reasonable, as far as the examples go. @folkertdev Could you please add some examples that include very long left-hand sides in Please include both examples where the line is overlong, and examples where the user manually wrapped the left-hand side. |
5b15896
to
89a83da
Compare
I added some formatting examples. They do in fact already format nicely. I did just notice that comments on the branches, like below, disappear upon formatting cfg_select! {
// This comment will disappear when formatting.
any(true) => {}
} For Does |
For context, @joshtriplett and I talked about this in the style team meeting, and @folkertdev, if you're interested in working with us on it, we were interested in using this PR to explore possible solutions to the questions we had raised about how to format this, such as what Josh mentioned about long left-hand sides. If we can work out some good rules in this PR, and use the test cases in it to verify that we're happy with the formatting of all the hard cases that we can think of, then we can write down the rules in the style guide around the behavior that's proposed and that we agree on here. Generally, our preference, if possible, is some wrapping rule for the LHS that keeps things below the maximum column width and that we can later apply, over a style edition, to normal |
89a83da
to
08240dd
Compare
well, I'd like to see I added some of the long unbreakable line examples, just so we track their behavior. There we also see that comments inside of the block are dropped which is a bit strange because there we just give a tokenstream to the formatter, and I would have assumed that it handled comments. For the simple cases I think the current behavior is what we want right? though I assume the |
08240dd
to
ccfa107
Compare
This comment has been minimized.
This comment has been minimized.
The trouble is that rustfmt's stability policy is that once it formats a construct, the formatting must remain byte-identical within that style edition. So whatever our behavior for the non-simple cases ends up being what we have to commit to and document in the style guide. So it's better if we can come up with reasonable rules for the non-common cases as well, so that we can commit to reasonable behavior for those cases too. We're open to and interested in seeing proposed behavior there as part of this PR. |
ccfa107
to
17d516f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I just meant to say that what we need is refinement, but the broad strokes work as desired.
// The cfg plus ` => {` should stay within the line length. | ||
let rule_shape = shape | ||
.sub_width(" => {".len()) | ||
.max_width_error(shape.width, span)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to have the desired effect, am I using this right?
any(feature = "acdefg", true, true, true, true, true, true, true, true) => { | ||
compile_error!("foo") | ||
} | ||
any(feature = "acdefgh123", true, true, true, true, true, true, true, true) => { | ||
compile_error!("foo") | ||
} | ||
any( | ||
feature = "acdefgh1234", | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true | ||
) => { | ||
compile_error!("foo") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently this breaks when the cfg
part exceeds 80 characters. I've tried to take the => {
into account, but that doesn't seem to have any effect. Also when the rhs really is empty, we'd need to consider => {}
for the length.
The above still has issues with comments too, which I'm not sure how to deal with.
So @ytmimi @calebcartwright a rustfmt review is probably also a good idea at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a very brief look at this the other day and I had some suggestions for changes. I'll do my best to wrap up my review soon.
tracking issue: #115585
Done here because
rust-lang/rustfmt
has not been synced for a while and uses a nightly version wherecfg_select!
is not yet a builtin macro.r? @ytmimi