Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
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
    C-bug
    regression-untriaged
    on Jun 24, 2026
  2. added
    needs-triage
    I-prioritize
    on Jun 24, 2026
  3. added
    T-rustfmt
    on Jun 24, 2026
  4. tgross35 commented on Jun 24, 2026

    @tgross35
    Member

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

  5. removed
    needs-triage
    on Jun 25, 2026
  6. removed
    I-prioritize
    on Jun 26, 2026
  7. rustbot commented on Jun 26, 2026

    @rustbot
    Collaborator

    Assigning P-medium (discussion on Zulip).

  8. added
    P-medium
    on Jun 26, 2026
  9. added a commit that references this issue on Jul 24, 2026
  10. added a commit that references this issue on Jul 24, 2026
  11. added a commit that references this issue on Nov 12, 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-bugP-mediumT-rustfmtregression-untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions