Uh oh!
There was an error while loading. Please reload this page.
rustfmt: Format cfg_select! - #154202
Conversation
rustbot
commented
Mar 22, 2026
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
rustbot
commented
Mar 22, 2026
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Uh oh!
There was an error while loading. Please reload this page.
| // trailing comments on the last line are a little buggy and always wrap back up | ||
| cfg_select! { | ||
| windows => { | ||
| "windows" | ||
| } | ||
| unix => { | ||
| "unix" | ||
| } | ||
| _ => { | ||
| "none" | ||
| } // FIXME. Prevent wrapping back up to the next line | ||
| } | ||
| cfg_select! { | ||
| windows => "windows", | ||
| unix => "unix", | ||
| _ => "none", // FIXME. Prevent wrapping back up to the next line | ||
| } |
There was a problem hiding this comment.
A pre-existing issue with trailing comments in rustfmt. I wanted to explicitly capture the current behavior in a test case.
| // Can't format cfg_select! at all with style_edition <= 2021. | ||
| // Things can be formatted with style_edition >= 2024 | ||
| cfg_select! { | ||
| feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff" => | ||
| { | ||
| // abc | ||
| println!(); | ||
| } | ||
| feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff" => | ||
| { | ||
| // abc | ||
| } | ||
| all(anything( | ||
| "some other long long long long long thing long long long long long long long long long long long", | ||
| feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff" | ||
| )) => { | ||
| let x = 7; | ||
| } | ||
| } |
There was a problem hiding this comment.
Through some testing I found that in style_edition <= 2021 this example won't be formatted at all because the predicate can't be formatted within max_width, but with style_edition >= 2024 that's not an issue.
| // comments within the predicate are fine with style_edition=2024+ | ||
| cfg_select! { | ||
| any( | ||
| true, /* comment */ | ||
| true, true, // true, | ||
| true, | ||
| ) => {} | ||
| not( | ||
| false // comment | ||
| ) => {} | ||
| any( | ||
| false // comment | ||
| ) => "any", | ||
| } |
There was a problem hiding this comment.
Not the best place for a comment to begin with IMO, but I wanted to call out that comments within the predicate aren't correctly handled in style_edition <= 2021. This is how the current example is formatted:
cfg_select!{
any(true,/* comment */true,true,// true,true,) => {}
not(false// comment) => {}
any(false// comment) => "any",}Clearly that's wrong and produces invalid code, but fixing this seems like it's outisde the scope of this PR. since it only impacts style_edition <= 2021.
Maybe this is something we can address later?
There was a problem hiding this comment.
I agree, I think we shouldn't try to bundle that in this PR. We probably should open an issue in rustfmt/r-l/r to track this as a known-bug though.
Uh oh!
There was an error while loading. Please reload this page.
jieyouxu
commented
Mar 23, 2026
(I'll gradually review this; need to build up some background ctx first.) |
There was a problem hiding this comment.
Thanks! The impl broadly looks good to me, just some minor nits and a few test coverage discussions.
@rustbot author
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| // comments within the predicate are fine with style_edition=2024+ | ||
| cfg_select! { | ||
| any( | ||
| true, /* comment */ | ||
| true, true, // true, | ||
| true, | ||
| ) => {} | ||
| not( | ||
| false // comment | ||
| ) => {} | ||
| any( | ||
| false // comment | ||
| ) => "any", | ||
| } |
There was a problem hiding this comment.
I agree, I think we shouldn't try to bundle that in this PR. We probably should open an issue in rustfmt/r-l/r to track this as a known-bug though.
| // comments before and after the `=>` get dropped right now | ||
| cfg_select! { | ||
| any(true, true, true, true,) => {} | ||
| not(false) => {} | ||
| any(false) => "any", | ||
| } |
There was a problem hiding this comment.
Question: this should also a "known bug" right? Should we also include a follow-up issue to track this?
There was a problem hiding this comment.
Yeah, I think we can create an issue for it. I'll handle that after the initial formatting lands
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rustbot
commented
Mar 30, 2026
Reminder, once the PR becomes ready for a review, use |
There was a problem hiding this comment.
Backlinks / context for myself (and future travellers):
Metadata
- Library feature:
cfg_select - std docs: https://doc.rust-lang.org/nightly/std/macro.cfg_select.html
- Tracking issue: Tracking issue for
cfg_select(formerlycfg_match) #115585 - Style team discussion: Formatting for cfg_select style-team#201
- Reference update PR:
cfg_select!macro reference#2103
History
Initial style team discussions
- The arms must be wrapped in braces, so
rustfmtwill have to ensure to not remove those.
Follow-up: unbraced expressions are permitted
PR: #145233
This comment has been minimized.
This comment has been minimized.
…es, r=ytmimi,jieyouxu rustfmt: Discover modules via `cfg_select!` This PR renames all occurrences of `cfg_match!` in rustfmt to `cfg_select!`. This makes the module file detection logic from rust-lang/rustfmt#6522 kick in for `cfg_select!` instead of `cfg_match!`, which no longer exists. This PR performs no other adjustments to the logic to be as small as possible. I am opening this PR in this repo since that is also the target for the more comprehensive rust-lang#154202, which covers more than merely detecting other files through `cfg_select!`. Closesrust-lang#158371. CC: @ytmimi, @CAD97
Rollup merge of #158372 - mkroening:rustfmt-cfg_select-modules, r=ytmimi,jieyouxu rustfmt: Discover modules via `cfg_select!` This PR renames all occurrences of `cfg_match!` in rustfmt to `cfg_select!`. This makes the module file detection logic from rust-lang/rustfmt#6522 kick in for `cfg_select!` instead of `cfg_match!`, which no longer exists. This PR performs no other adjustments to the logic to be as small as possible. I am opening this PR in this repo since that is also the target for the more comprehensive #154202, which covers more than merely detecting other files through `cfg_select!`. Closes#158371. CC: @ytmimi, @CAD97
…imi,jieyouxu rustfmt: Discover modules via `cfg_select!` This PR renames all occurrences of `cfg_match!` in rustfmt to `cfg_select!`. This makes the module file detection logic from rust-lang/rustfmt#6522 kick in for `cfg_select!` instead of `cfg_match!`, which no longer exists. This PR performs no other adjustments to the logic to be as small as possible. I am opening this PR in this repo since that is also the target for the more comprehensive rust-lang/rust#154202, which covers more than merely detecting other files through `cfg_select!`. Closesrust-lang/rust#158371. CC: @ytmimi, @CAD97
`cfg_select!` parsing needs to be implemented in rustfmt right now because there's no good way to call `rustc_attr_parsing::parse_cfg_select`.
The plan is to leverage `rewrite_match_body` to help with `cfg_select!` formatting.
| // Doesn't parse as expected so this is handled by the default macro handling | ||
| cfg_select! ( | ||
| A + B + C | ||
| ); | ||
| cfg_select! [ | ||
| A + B + C | ||
| ]; | ||
| // rustfmt doesn't format macros with brace delimiters | ||
| cfg_select! { | ||
| A + B + C | ||
| } |
There was a problem hiding this comment.
Remark: good call, I forgot about this coverage
rustfmt: Format `cfg_select!` tracking issue: rust-lang#115585 Implementing `cfg_select!` formatting here in `rust-lang/rust` so that the feature can get out to nightly quicker. The previous PR (rust-lang#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR. I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time. --- Previous PR: * rust-lang#144323 See also: * rust-lang/style-team#201
rustfmt: Format `cfg_select!` tracking issue: rust-lang#115585 Implementing `cfg_select!` formatting here in `rust-lang/rust` so that the feature can get out to nightly quicker. The previous PR (rust-lang#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR. I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time. --- Previous PR: * rust-lang#144323 See also: * rust-lang/style-team#201
rustfmt: Format `cfg_select!` tracking issue: rust-lang#115585 Implementing `cfg_select!` formatting here in `rust-lang/rust` so that the feature can get out to nightly quicker. The previous PR (rust-lang#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR. I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time. --- Previous PR: * rust-lang#144323 See also: * rust-lang/style-team#201
…uwer Rollup of 21 pull requests Successful merges: - #160100 (Add "system" option to `override-allocator` directive) - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - #160233 (Bubble bad path error while parsing field to avoid unecessary second error) - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - #154202 (rustfmt: Format `cfg_select!`) - #158835 (rustc_passes: lint unused `#[path]` attributes on inline modules) - #159520 (Suggest `Vec<T>` instead of `[T]`) - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - #160066 (rustc_middle: lint attribute cleanups) - #160085 (Remove various superfluous lint attributes) - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - #160157 (Remove outdated comments from `va_list.rs`) - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - #160244 (Rename splat to rustc_splat in error messages) - #160246 (dont fire `unused_mut` on `&pin mut self`) - #160247 (Configure backport nominations for rustfmt) - #160274 (renovate: update lock files weekly)
…uwer Rollup of 22 pull requests Successful merges: - #160100 (Add "system" option to `override-allocator` directive) - #160220 (Refactor: shrink region ext traits) - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - #160233 (Bubble bad path error while parsing field to avoid unecessary second error) - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - #154202 (rustfmt: Format `cfg_select!`) - #159520 (Suggest `Vec<T>` instead of `[T]`) - #159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts) - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - #160066 (rustc_middle: lint attribute cleanups) - #160085 (Remove various superfluous lint attributes) - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - #160157 (Remove outdated comments from `va_list.rs`) - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - #160244 (Rename splat to rustc_splat in error messages) - #160246 (dont fire `unused_mut` on `&pin mut self`) - #160247 (Configure backport nominations for rustfmt) - #160274 (renovate: update lock files weekly)
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #154202 - ytmimi:format_cfg_select, r=jieyouxu rustfmt: Format `cfg_select!` tracking issue: #115585 Implementing `cfg_select!` formatting here in `rust-lang/rust` so that the feature can get out to nightly quicker. The previous PR (#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR. I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time. --- Previous PR: * #144323 See also: * rust-lang/style-team#201
…uwer Rollup of 22 pull requests Successful merges: - rust-lang/rust#160100 (Add "system" option to `override-allocator` directive) - rust-lang/rust#160220 (Refactor: shrink region ext traits) - rust-lang/rust#159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - rust-lang/rust#159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - rust-lang/rust#160233 (Bubble bad path error while parsing field to avoid unecessary second error) - rust-lang/rust#160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - rust-lang/rust#154202 (rustfmt: Format `cfg_select!`) - rust-lang/rust#159520 (Suggest `Vec<T>` instead of `[T]`) - rust-lang/rust#159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts) - rust-lang/rust#160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - rust-lang/rust#160066 (rustc_middle: lint attribute cleanups) - rust-lang/rust#160085 (Remove various superfluous lint attributes) - rust-lang/rust#160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - rust-lang/rust#160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - rust-lang/rust#160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - rust-lang/rust#160157 (Remove outdated comments from `va_list.rs`) - rust-lang/rust#160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - rust-lang/rust#160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - rust-lang/rust#160244 (Rename splat to rustc_splat in error messages) - rust-lang/rust#160246 (dont fire `unused_mut` on `&pin mut self`) - rust-lang/rust#160247 (Configure backport nominations for rustfmt) - rust-lang/rust#160274 (renovate: update lock files weekly)
…matting, r=jieyouxu rustfmt: restrict `cfg_select!` formatting to the `nightly` release channel Closes: rust-lang#160944 `cfg_select!` formatting was implemented in rust-lang#154202. The formatting diverged from what was outlined in the original Style FCP (rust-lang/style-team#201 (comment) and rust-lang#144323 (comment)). Since the 1.99 beta is scheduled to branch from main on August 14 I want to get this nightly formatting gate out so that we can correct the formatting issues before we promote the formatting to the beta / stable release channels. Style Guide PR: rust-lang#160967 r? @jieyouxu cc: @traviscross
Rollup merge of #160998 - ytmimi:nightly_only_cfg_select_formatting, r=jieyouxu rustfmt: restrict `cfg_select!` formatting to the `nightly` release channel Closes: #160944 `cfg_select!` formatting was implemented in #154202. The formatting diverged from what was outlined in the original Style FCP (rust-lang/style-team#201 (comment) and #144323 (comment)). Since the 1.99 beta is scheduled to branch from main on August 14 I want to get this nightly formatting gate out so that we can correct the formatting issues before we promote the formatting to the beta / stable release channels. Style Guide PR: #160967 r? @jieyouxu cc: @traviscross
…uwer Rollup of 22 pull requests Successful merges: - rust-lang/rust#160100 (Add "system" option to `override-allocator` directive) - rust-lang/rust#160220 (Refactor: shrink region ext traits) - rust-lang/rust#159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - rust-lang/rust#159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - rust-lang/rust#160233 (Bubble bad path error while parsing field to avoid unecessary second error) - rust-lang/rust#160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - rust-lang/rust#154202 (rustfmt: Format `cfg_select!`) - rust-lang/rust#159520 (Suggest `Vec<T>` instead of `[T]`) - rust-lang/rust#159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts) - rust-lang/rust#160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - rust-lang/rust#160066 (rustc_middle: lint attribute cleanups) - rust-lang/rust#160085 (Remove various superfluous lint attributes) - rust-lang/rust#160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - rust-lang/rust#160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - rust-lang/rust#160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - rust-lang/rust#160157 (Remove outdated comments from `va_list.rs`) - rust-lang/rust#160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - rust-lang/rust#160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - rust-lang/rust#160244 (Rename splat to rustc_splat in error messages) - rust-lang/rust#160246 (dont fire `unused_mut` on `&pin mut self`) - rust-lang/rust#160247 (Configure backport nominations for rustfmt) - rust-lang/rust#160274 (renovate: update lock files weekly)
View all comments
tracking issue: #115585
Implementing
cfg_select!formatting here inrust-lang/rustso that the feature can get out to nightly quicker.The previous PR (#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR.
I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time.
Previous PR:
cfg_select#144323See also: