Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
boozook opened this issue Oct 19, 2020 · 4 comments
Open

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

boozook opened this issue Oct 19, 2020 · 4 comments
Labels
a-mods Module resolution. bug Panic, non-idempotency, invalid code, etc. os-windows p-medium

Comments

@boozook
Copy link

boozook commented Oct 19, 2020

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
@boozook boozook added the bug Panic, non-idempotency, invalid code, etc. label Oct 19, 2020
@calebcartwright
Copy link
Member

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

boozook added a commit to dfinance/move-tools that referenced this issue Oct 20, 2020
fix rustfmt-check fail on windows
(rel issue: rust-lang/rustfmt#4477)
@boozook
Copy link
Author

boozook commented Oct 20, 2020

...
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")

@francis-du
Copy link

francis-du commented Dec 10, 2020

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

@chadbrewbaker
Copy link

Just now I did a :

rustup component add rustfmt --toolchain nightly 

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-mods Module resolution. bug Panic, non-idempotency, invalid code, etc. os-windows p-medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants