`#[cfg_attr(..., path = ...)]` on inline modules is not recognized
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.