Skip to content

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

Description

@purplesyringa
// 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-cfgArea: `cfg` and conditional compilationA-modulesArea: module resolutionC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions