rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Rustfmt cannot find mod with #[path] on windows

Open boozook opened this issue 5 years ago • 4 comments

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 (530eadf4 2020-06-02)
    • rustfmt 1.4.15-nightly (aedff61f 2020-05-19)
  • From where did you install rustfmt?: rustup, crates.io
  • How do you run rustfmt: rustfmt, cargo-fmt

boozook avatar Oct 19 '20 13:10 boozook

rustfmt versions:

* rustfmt 1.4.15-stable ([530eadf](https://github.com/rust-lang/rustfmt/commit/530eadf4b42ddf35b209d4f4acd120f3fcc467ce) 2020-06-02)

* rustfmt 1.4.15-nightly ([aedff61](https://github.com/rust-lang/rustfmt/commit/aedff61f7ac4fc2b287ff76d33f2584e1f63a3af) 2020-05-19)

Could you try with a more recent version? There were a lot of improvements on the module resolution in 1.4.20/1.4.22 if I recall correctly

calebcartwright avatar Oct 20 '20 00:10 calebcartwright

... Could you try with a more recent version? There were a lot of improvements on the module resolution in 1.4.20/1.4.22 if I recall correctly

@calebcartwright, I'm sorry, versions I previously mentioned is my local. But latest rustfmt on CI, there is rustfmt 1.4.20-stable (48f6c32e 2020-08-09) and rustfmt 1.4.22-nightly (97d03010 2020-10-04). (proof, see "print versions")

boozook avatar Oct 20 '20 10:10 boozook

Same problem on rustfmt 1.4.22-nightly (97d03010 2020-10-04) and rustfmt 1.4.22-nightly (97d03010 2020-10-04)

ERRORS:

> cargo fmt 

error: couldn't read \\?\F:\Rust\tikv\components\cdc\tests\failpoints\..\mod.rs: 文件名、目录名或卷标语法不正确。 (os error 123)

Error writing files: failed to resolve mod `testsuite`: \\?\F:\Rust\tikv\components\cdc\tests\failpoints\..\mod.rs does not exist
error: couldn't read \\?\F:\Rust\tikv\components\cdc\tests\integrations\..\mod.rs: 文件名、目录名或卷标语法不正确。 (os error 123)

Error writing files: failed to resolve mod `testsuite`: \\?\F:\Rust\tikv\components\cdc\tests\integrations\..\mod.rs does not exist
error: couldn't read \\?\F:\Rust\tikv\tests\failpoints\cases\..\..\integrations\import\util.rs: 文件名、目录名或卷标语法不正确。 (os error 123)

Error writing files: failed to resolve mod `util`: \\?\F:\Rust\tikv\tests\failpoints\cases\..\..\integrations\import\util.rs does not exist

francis-du avatar Dec 10 '20 23:12 francis-du

Just now I did a :

rustup component add rustfmt --toolchain nightly 

Says it installed but Windows couldn't find the path.

chadbrewbaker avatar Feb 23 '21 20:02 chadbrewbaker