Skip to content

Rustfmt cannot find mod with #[path] on windows #4477

Open
@boozook

Description

@boozook

Rustfmt on windows cannot resolve module to file if #[path] used.

Note, #[path] should contain windows-unfriendly relative path.

To Reproduce

Use #[path = "./some-relative-path.rs"] in code.
Pointed file should be and valid rust source or empty.

#[path = "../module_foo.rs"]
mod module_foo;

Error:

> cargo fmt -- --check
error: couldn't read \\?\D:\a\rustfmt-issue-4477\rustfmt-issue-4477\src\..\module_foo.rs: The filename, directory name, or volume label syntax is incorrect. (os error 123)
Error writing files: failed to resolve mod `module_foo`: \\?\D:\a\rustfmt-issue-4477\rustfmt-issue-4477\src\..\module_foo.rs does not exist

Check out demo for this issue. Also there is two cases reproduced on GHA:

  1. this error "file not found"
  2. all is ok, #[path] with just filename

Expected behavior

No rustfmt's IO errors.
All modules resolved.

Meta

  • rustfmt versions:
    • rustfmt 1.4.15-stable (530eadf 2020-06-02)
    • rustfmt 1.4.15-nightly (aedff61 2020-05-19)
  • From where did you install rustfmt?: rustup, crates.io
  • How do you run rustfmt: rustfmt, cargo-fmt

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-modsModule resolution.bugPanic, non-idempotency, invalid code, etc.os-windowsp-medium

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions