Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

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.


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. :)

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.
@joshtriplett joshtriplett added T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-lang-nominated Nominated for discussion during a lang team meeting. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Aug 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 10, 2025
Comment on lines +27 to +28
/// Parses a `TokenTree` consisting either of `{ /* ... */ }` (and strip the braces) or an
/// expression followed by a comma (and strip the comma).
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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 🤔

Copy link
Contributor

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.

Copy link
Member Author

@joshtriplett joshtriplett Aug 12, 2025

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.

@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Aug 12, 2025
@Amanieu
Copy link
Member

Amanieu commented Aug 12, 2025

We discussed this in the @rust-lang/libs-api meeting and everyone was happy with this change.

@joshtriplett joshtriplett removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Aug 13, 2025
@traviscross
Copy link
Contributor

We discussed this in the lang meeting. We were all happy to see this land in nightly. Thanks to @joshtriplett for putting this forward.

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants