-
Notifications
You must be signed in to change notification settings - Fork 14.1k
stabilize cfg_select!
#149783
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: main
Are you sure you want to change the base?
stabilize cfg_select!
#149783
Conversation
This comment has been minimized.
This comment has been minimized.
c4d3570 to
0e24d24
Compare
This comment has been minimized.
This comment has been minimized.
0e24d24 to
c87e26a
Compare
This comment has been minimized.
This comment has been minimized.
c87e26a to
67d1d43
Compare
|
Happy to see this move forward! Is there a detailed description of how this macro works? For example:
|
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 The Miri subtree was changed cc @rust-lang/miri |
Not yet, I think.
In item positions the body should consist of zero or more In expression position we additionally accept
That is correct, one level of braces is removed if braces are used.
Yes if none of the conditions evaluate to true you'll get a compile error (note: earlier iterations did not have this default behavior)
The ecosystem mostly uses
I don't think there is a reason. We could make it a lint (or add it to an existing one?)
Yes, the rhs can be any token tree. |
For my part, it seems worth doing this. Then we can stabilize this lint along with this FCP. Perhaps a new lint named (In the alternate, if we did want "predicate" in the name, I'd suggest |
tracking issue: #115585
closes #115585
reference PR:
cfg_select!macro reference#2103Request for Stabilization
Summary
The
cfg_select!macro picks the expansion corresponding to the firstcfgcondition that evaluates totrue. It simplifies complex conditional expressions.Semantics
The expansion of a
cfg_select!call is the right-hand side of the firstcfgrule that evaluates to true.This can be roughly expressed using this macro:
The actual implementation uses a builtin macro so that
cfg_select!can be used both in item and expression position.Documentation
reference PR:
cfg_select!macro reference#2103Tests
The
cfg_select!macro is already used extensively in the rust compiler codebase. It has several dedicated tests:tests/ui/check-cfg/cfg-select.rstests that warnings are emitted when an unexpectedcfgcondition is used.tests/ui/macros/cfg_select.rstests thatcfg_select!has the expected expansion, and tests that the expected syntax is accepted.History
cfg_match!macro #115416cfg_matchfrom the prelude #117162cfg_match!tocfg_select!#137198cfg_match!a semitransparent macro #138993cfg_match!in core #138996cfg_selecta builtin macro #143461cfg_select!documentation #143941cfg_select!to the new attribute parsing system #148712eval_config_entryon all branches so we always emit lints #149380Resolved questions
Unresolved questions
The style team has decided on how to format
cfg_select!, but this formatting has not yet been implemented. See #144323.r? @traviscross