Skip to content

rustfmt does not discover modules through cfg_select! #158371

Closed

Description

@mkroening

In case this issue is a better fit for the rustfmt repo, feel free to move it there. Also, if this is not a good fit for the regression tag, please change it.

Given this lib.rs and corresponding module files:

cfg_match! {
    target_family = "unix" => {
        mod format_me_please_1;
    }
    _ => {
        mod format_me_please_2;
    }
}

When formatting this, everything is fine:

$ rustfmt src/lib.rs --verbose
Formatting src/format_me_please_1.rs
Formatting src/format_me_please_2.rs
Formatting src/lib.rs
Spent 0.004 secs in the parsing phase, and 0.002 secs in the formatting phase

Support for detecting module files through cfg_match! was addded in rust-lang/rustfmt#6522. But cfg_match! was renamed to cfg_select! in #137198, and if you change the code above to say cfg_select!, it no longer detects the module files:

$ rustfmt src/lib.rs --verbose
Formatting src/lib.rs
Spent 0.002 secs in the parsing phase, and 0.001 secs in the formatting phase

So anyone who has used cfg_select! to define modules in other files has possibly unformatted files. This is especially relevant due to the recent stabilization of cfg_select! (#149783) the migration from cfg_if! to cfg_select! in the ecosystem (e.g., rust-lang/compiler-builtins#1224).

#154202 does not appear to fix this issue. Renaming the corresponding occurrences in rustfmt fixes the issue for me, so I have opened #158372.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 24, 2026
  2. added
    T-rustfmtRelevant to the rustfmt team, which will review and decide on the PR/issue.
    on Jun 24, 2026
  3. tgross35 commented on Jun 24, 2026

    @tgross35
    Member

    Started a Zulip discussion #t-rustfmt > cfg_select module discovery

  4. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 25, 2026
  5. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 26, 2026
  6. rustbot commented on Jun 26, 2026

    @rustbot
    Collaborator

    Assigning P-medium (discussion on Zulip).

  7. added a commit that references this issue on Jul 24, 2026
  8. added a commit that references this issue on Jul 24, 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.P-mediumMedium priorityT-rustfmtRelevant to the rustfmt team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions