-
Notifications
You must be signed in to change notification settings - Fork 13.6k
cfg_select: Support unbraced expressions #145233
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?
Conversation
When operating on expressions, `cfg_select!` can now handle expressions without braces. (It still requires braces for other things, such as items.) Expand the test coverage and documentation accordingly.
/// Parses a `TokenTree` consisting either of `{ /* ... */ }` (and strip the braces) or an | ||
/// expression followed by a comma (and strip the comma). |
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.
Question: do you know why cfg_select!
required braces previously? Did this have any grammar ambiguity problems?
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.
When it was not a built-in macro, I think it was needed to handle expressions. Once it became a built-in macro, I think it was just simplicity of implementation.
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.
Interesting. This would probably require #144323 to change again 🤔
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.
Changing it is fine, but I don't really see a way here to decide whether to format with the comma or as a block? For match
that is based on whether there is a statement (i.e. a ;
) in the rhs, here I don't see how we can decide when the ,
variant is desired, unless the formatter should always use a ,
in expression position?
Alternatively we just stick with the user's formatting choice, in which case that information needs to be stored.
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.
@folkertdev I think the right answer there would be to determine whether it needs to be wrapped onto a new line, and if it doesn't, and it's an expression, write it without braces and using a ,
. That's similar to how match
is handled other than the "is an expression" check.
We discussed this in the @rust-lang/libs-api meeting and everyone was happy with this change. |
We discussed this in the lang meeting. We were all happy to see this land in nightly. Thanks to @joshtriplett for putting this forward. |
When operating on expressions,
cfg_select!
can now handle expressionswithout braces. (It still requires braces for other things, such as
items.)
Expand the test coverage and documentation accordingly.
I'm not sure whether deciding to extend
cfg_select!
in this way is T-lang or T-libs-api. I've labeled for both, with the request that both teams don't block on each other. :)