rust-lang / rust-lang/rustfmt

`#[cfg_attr(..., path = ...)]` on inline modules is not recognized

Open
#7,038 2 comments 0 reactions 1 assignee View on GitHub

@ytmimi is already working on this.

Since Aug 21, 2026.

A-cfg A-modules C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

// lib.rs
#[cfg_attr(unix, path = "meow_unix")]
#[cfg_attr(not(unix), path = "meow_not_unix")]
mod meow {
    mod mrrp;
}

// meow_unix/mrrp.rs
broken

// meow_not_unix/mrrp.rs
broken
$ cargo fmt
Error writing files: failed to resolve mod `mrrp`: /home/purplesyringa/rust-test/src/meow/mrrp.rs does not exist

Creating meow/mrrp.rs removes the error message, but doesn't format the (broken) included files.

This is a variant of #2407, which was fixed by #3604, but apparently not for path attributes on inline mod blocks. The correct path resolution here is to have meow::mrrp refer either to meow_unix/mrrp.rs or meow_not_unix/mrrp.rs, and indeed rustc sees it this way (reference), but rustfmt doesn't. This specifically affects path behind cfg_attr; normal path works correctly.

Meta

rustfmt --version:

rustfmt 1.10.0-nightly (f7d782a3be 2026-08-19)

@rustbot label +A-cfg +A-modules

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.