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

Error writing files: io error: Failed to find module #3901

Closed
dtolnay opened this issue Nov 3, 2019 · 2 comments · Fixed by #4194
Closed

Error writing files: io error: Failed to find module #3901

dtolnay opened this issue Nov 3, 2019 · 2 comments · Fixed by #4194
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@dtolnay
Copy link
Member

dtolnay commented Nov 3, 2019

I have two source files:

src/lib.rs

#[path = "."]
pub mod a {
    pub mod b;
}

src/b.rs

// (empty file)

cargo check seems to be fine with this layout, and the code compiles. But cargo fmt fails with:

Error writing files: io error: Failed to find module b in "." None
@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Nov 5, 2019
@josephlr
Copy link

I've also hit this issue. It seems like rustfmt does not like path-renamed modules.

mahkoh added a commit to mahkoh/rustfmt that referenced this issue May 21, 2020
Path attributes with relative paths were previously not treated as
relative to the containing file but as relative to the current working
directory of rustfmt.

The SubModKind enum had a dedicated variant for inner modules with
paths. However, the ordinary variant for inner modules also handles the
presence of path attributes and treats them correctly. Therefore the fix
is to simply remove the dedicated enum variant.

Fixes rust-lang#3901
Fixes rust-lang#4076
mahkoh added a commit to mahkoh/rustfmt that referenced this issue May 22, 2020
Path attributes with relative paths were previously not treated as
relative to the containing file but as relative to the current working
directory of rustfmt.

The SubModKind enum had a dedicated variant for inner modules with
paths. However, the ordinary variant for inner modules also handles the
presence of path attributes and treats them correctly. Therefore the fix
is to simply remove the dedicated enum variant.

Fixes rust-lang#3901
Fixes rust-lang#4076
@nocker01
Copy link

nocker01 commented Jul 14, 2020

Hi, I think I'm still experiencing this issue. I'm new to Rust...

I am using relative paths to access different modules. My project compiles fine but "cargo fmt" does not work for me. I'm using Windows 7 and have switched to a nightly build of rustup:
rustup 1.22.1 (b01adbbc3 2020-07-08)
nightly-i686-pc-windows-gnu

Previously when I ran the command "cargo fmt" I would get the error that is the subject of this thread. I now when I run it I get the following error:
error: couldn't read \?\C:\projects\application\main..\common\debug.rs: The filename, directory name, or volume label syntax is incorrect. (os error 123)
Error writing files: failed to resolve mod debug: \?\C:\projects\application\main..\common\debug.rs does not exist

This does tell me more clearly the path that could not be found but the file is definately in the directory:
C:\projects\application\common\debug.rs

EDIT: I should say my directory structure is:
C:\projects\application\common\debug.rs
C:\projects\application\main\main.rs

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

Successfully merging a pull request may close this issue.

4 participants