Port cfg_select! to the new attribute parsing system#148712
Port cfg_select! to the new attribute parsing system#148712bors merged 3 commits intorust-lang:mainfrom
cfg_select! to the new attribute parsing system#148712Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs |
|
|
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
1125b68 to
cf6d5c1
Compare
|
Some changes occurred in compiler/rustc_attr_parsing |
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
cf6d5c1 to
90f36af
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| ) -> Result<CfgSelectBranches, ErrorGuaranteed> { | ||
| let mut branches = CfgSelectBranches::default(); | ||
|
|
||
| while p.token != token::Eof { |
There was a problem hiding this comment.
this makes me so sad but for now we'll have to...
|
@bors r+ rollup |
|
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…szelmann Port `cfg_select!` to the new attribute parsing system Best reviewed commit by commit, since it involves some moving around of code r? ``@jdonszelmann``
…szelmann Port `cfg_select!` to the new attribute parsing system Best reviewed commit by commit, since it involves some moving around of code r? ```@jdonszelmann```
Rollup of 9 pull requests Successful merges: - #148480 (Add `Steal::risky_hack_borrow_mut`) - #148608 (Add test for --test-builder success path) - #148667 (a few small clippy fixes) - #148712 (Port `cfg_select!` to the new attribute parsing system) - #148760 (rustc_target: hide TargetOptions::vendor) - #148775 (Fix a typo in the documentation for the strict_shr function) - #148779 (Implement DynSend and DynSync for std::panic::Location.) - #148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - #148791 (fix "is_closure_like" doc comment) r? `@ghost` `@rustbot` modify labels: rollup
…szelmann Port `cfg_select!` to the new attribute parsing system Best reviewed commit by commit, since it involves some moving around of code r? ````@jdonszelmann````
Rollup of 13 pull requests Successful merges: - #148694 (std: support `RwLock` and thread parking on TEEOS) - #148712 (Port `cfg_select!` to the new attribute parsing system) - #148760 (rustc_target: hide TargetOptions::vendor) - #148771 (IAT: Reinstate early bailout) - #148775 (Fix a typo in the documentation for the strict_shr function) - #148779 (Implement DynSend and DynSync for std::panic::Location.) - #148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - #148783 (add test for assoc type norm wf check) - #148785 (Replace `master` branch references with `main`) - #148791 (fix "is_closure_like" doc comment) - #148792 (Prefer to use file.stable_id over file.name from source map) - #148805 (rustc-dev-guide subtree update) - #148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #148712 - JonathanBrouwer:cfg_select, r=jdonszelmann Port `cfg_select!` to the new attribute parsing system Best reviewed commit by commit, since it involves some moving around of code r? `````@jdonszelmann`````
Rollup of 13 pull requests Successful merges: - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang/rust#148771 (IAT: Reinstate early bailout) - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang/rust#148783 (add test for assoc type norm wf check) - rust-lang/rust#148785 (Replace `master` branch references with `main`) - rust-lang/rust#148791 (fix "is_closure_like" doc comment) - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang/rust#148805 (rustc-dev-guide subtree update) - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang/rust#148771 (IAT: Reinstate early bailout) - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang/rust#148783 (add test for assoc type norm wf check) - rust-lang/rust#148785 (Replace `master` branch references with `main`) - rust-lang/rust#148791 (fix "is_closure_like" doc comment) - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang/rust#148805 (rustc-dev-guide subtree update) - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang#148771 (IAT: Reinstate early bailout) - rust-lang#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang#148783 (add test for assoc type norm wf check) - rust-lang#148785 (Replace `master` branch references with `main`) - rust-lang#148791 (fix "is_closure_like" doc comment) - rust-lang#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang#148805 (rustc-dev-guide subtree update) - rust-lang#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang/rust#148771 (IAT: Reinstate early bailout) - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang/rust#148783 (add test for assoc type norm wf check) - rust-lang/rust#148785 (Replace `master` branch references with `main`) - rust-lang/rust#148791 (fix "is_closure_like" doc comment) - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang/rust#148805 (rustc-dev-guide subtree update) - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang/rust#148771 (IAT: Reinstate early bailout) - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang/rust#148783 (add test for assoc type norm wf check) - rust-lang/rust#148785 (Replace `master` branch references with `main`) - rust-lang/rust#148791 (fix "is_closure_like" doc comment) - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang/rust#148805 (rustc-dev-guide subtree update) - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS) - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system) - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor) - rust-lang/rust#148771 (IAT: Reinstate early bailout) - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function) - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.) - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - rust-lang/rust#148783 (add test for assoc type norm wf check) - rust-lang/rust#148785 (Replace `master` branch references with `main`) - rust-lang/rust#148791 (fix "is_closure_like" doc comment) - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map) - rust-lang/rust#148805 (rustc-dev-guide subtree update) - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
…=JonathanBrouwer stabilize `cfg_select!` *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/149783)* tracking issue: rust-lang#115585 closes rust-lang#115585 reference PR: - rust-lang/reference#2103 # Request for Stabilization ## Summary The `cfg_select!` macro picks the expansion corresponding to the first `cfg` condition that evaluates to `true`. It simplifies complex conditional expressions. ```rust cfg_select! { unix => { fn foo() { /* unix specific functionality */ } } target_pointer_width = "32" => { fn foo() { /* non-unix, 32-bit functionality */ } } _ => { fn foo() { /* fallback implementation */ } } } let is_unix_str = cfg_select! { unix => "unix", _ => "not unix", }; println!("{is_unix_str}"); ``` ## Semantics The expansion of a `cfg_select!` call is the right-hand side of the first `cfg` rule that evaluates to true. This can be roughly expressed using this macro: ```rust macro_rules! cfg_select { ({ $($tt:tt)* }) => {{ $crate::cfg_select! { $($tt)* } }}; (_ => { $($output:tt)* }) => { $($output)* }; ( $cfg:meta => $output:tt $($( $rest:tt )+)? ) => { #[cfg($cfg)] $crate::cfg_select! { _ => $output } $( #[cfg(not($cfg))] $crate::cfg_select! { $($rest)+ } )? } } ``` The actual implementation uses a builtin macro so that `cfg_select!` can be used both in item and expression position. ## Documentation reference PR: - rust-lang/reference#2103 ## Tests The `cfg_select!` macro is already used extensively in the rust compiler codebase. It has several dedicated tests: - [`tests/ui/check-cfg/cfg-select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/check-cfg/cfg-select.rs)tests that warnings are emitted when an unexpected `cfg` condition is used. - [`tests/ui/macros/cfg_select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/macros/cfg_select.rs) tests that `cfg_select!` has the expected expansion, and tests that the expected syntax is accepted. ## History - rust-lang#115416 - rust-lang#117162 - rust-lang#133720 - rust-lang#135625 - rust-lang#137198 - rust-lang#138993 - rust-lang#138996 - rust-lang#143461 - rust-lang#143941 - rust-lang#145233 - rust-lang#148712 - rust-lang#149380 - rust-lang#149925 # Resolved questions # Unresolved questions The style team has decided on how to format `cfg_select!`, but this formatting has not yet been implemented. See rust-lang#144323. r? @traviscross <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_CONCERN-ISSUE_START --> > [!NOTE] > # Concerns (0 active) > > - ~~[allowing-comma-after-closing-brace](rust-lang#149783 (comment) resolved in [this comment](rust-lang#149783 (comment)) > > *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.* <!-- TRIAGEBOT_CONCERN-ISSUE_END --> <!-- TRIAGEBOT_END -->
Best reviewed commit by commit, since it involves some moving around of code
r? @jdonszelmann