Skip to content

rustfmt can't understand configured module path attributes #2407

Closed
@fitzgen

Description

@fitzgen

I have a module that has different implementations depending on what the target is. I use #[cfg_attr(..., path = "...")] to choose the correct implementation.

https://github.com/fitzgen/wee_alloc/blob/master/wee_alloc/src/lib.rs#L237-L246

#[cfg(all(not(unix), not(target_arch = "wasm32")))]
compile_error! {
    "There is no `wee_alloc` implementation for this target; want to send a pull request? :)"
}

#[cfg_attr(target_arch = "wasm32",
           path = "./imp_wasm32.rs")]
#[cfg_attr(all(unix, not(target_arch = "wasm32")),
           path = "./imp_unix.rs")]
mod imp;

rustfmt seems unable to handle this:

$ cargo fmt --all
error[E0583]: file not found for module `imp`
   --> /home/fitzgen/wee_alloc/wee_alloc/src/lib.rs:246:5
    |
246 | mod imp;
    |     ^^^
    |
    = help: name the file either imp.rs or imp/mod.rs inside the directory "/home/fitzgen/wee_alloc/wee_alloc/src"

I would expect that it would use the host target by default, or otherwise maybe hit the compile_error or something.

$ cargo fmt --version
0.3.6-nightly (e0e3e22 2018-01-18)

Full Steps to Reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.p-high

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions