Skip to content

rustfmt formatting of cfg_select! pending for Rust 1.99 diverges from style FCP #160944

Closed

Description

@traviscross

In rust-lang/style-team#201 (comment), the style team FCPed a decision about how to format code within cfg_select. This included by reference the determination made in #144323 (comment). In that, we specified the following formatting:

cfg_select! {
    feature
        = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff"
    => {
        println!();
    }
    feature
        = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff"
    => {}
    anything(
        "some other long long long long long thing long long long long long long long long long long long",
    ) => {}
}

That PR was closed, and formatting for cfg_select! landed in #154202 (thanks for that!). But the current formatting, for the above, on nightly, is:

cfg_select! {
    feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff" =>
    {
        println!();
    }
    feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff" =>
        {}
    anything(
        "some other long long long long long thing long long long long long long long long long long long",
    ) => {}
}

It's also not adding trailing commas, so it formats this —

cfg_select! {
    all(target_arch = "x86_64", target_env = "gnu", not(any(target_os = "os1", target_os = "os2"))) => {}
    any(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen) => {}
    _ => {}
}

— as:

cfg_select! {
    all(
        target_arch = "x86_64",
        target_env = "gnu",
        not(any(target_os = "os1", target_os = "os2"))
    ) => {}
    any(
        one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen,
        fourteen, fifteen, sixteen
    ) => {}
    _ => {}
}

I'd suspect we might want it to add the trailing commas there.

@ytmimi: What are you thoughts on how to handle this given the pending beta bump?

cc @rust-lang/rustfmt @rust-lang/style

Activity

  1. added
    C-bugCategory: This is a bug.
    I-style-nominatedNominated for discussion during a style team meeting.
    T-styleRelevant to the style team, which will review and decide on the PR/issue.
    T-rustfmtRelevant to the rustfmt team, which will review and decide on the PR/issue.
    on Aug 11, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 11, 2026
  3. ytmimi commented on Aug 11, 2026

    @ytmimi
    Contributor

    @traviscross could we pull the formatting from the beta but keep it on nightly? I think we should try to adhere to the formatting rules that @rust-lang/style came up with.

    Are the rules officially incorporated in the style-guide? Would be nice to have them as a reference when updating the implementation.


    Edit: I guess to prevent this from landing on beta we could add a is_nightly_channel!() check to gate formatting

  4. traviscross commented on Aug 11, 2026

    @traviscross
    ContributorAuthor

    That would make sense to me; thanks. I'm working on a style guide PR.

  5. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 11, 2026
  6. traviscross commented on Aug 12, 2026

    @traviscross
    ContributorAuthor
  7. ytmimi commented on Aug 12, 2026

    @ytmimi
    Contributor

    PR to gate cfg_select! formatting on the nightly release channel:

  8. added a commit that references this issue on Aug 13, 2026
  9. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-style-nominatedNominated for discussion during a style team meeting.T-rustfmtRelevant to the rustfmt team, which will review and decide on the PR/issue.T-styleRelevant to the style team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions