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 is not able to find files internally #4076

Closed
vss96 opened this issue Mar 8, 2020 · 3 comments · Fixed by #4194
Closed

Rustfmt is not able to find files internally #4076

vss96 opened this issue Mar 8, 2020 · 3 comments · Fixed by #4194
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@vss96
Copy link

vss96 commented Mar 8, 2020

Hi,
I recently moved from importing using "mod.rs" to using path macro. So currently the directory inside src is [ main.rs, something/ a.rs (instead of mod.rs)]. When I run cargo fmt in the same level as src, this particular error is thrown.
Error writing files: io error: something/a.rs: No such file or directory (os error 2)
Interestingly enough, if I run cargo fmt inside the src directory, it works fine. I'm assuming that it's supposed to run on the same level as the toml file, so this is not an expected behavior?
Also, it works fine if I revert back a.rs to mod.rs.

Rust fmt version - rustfmt 1.4.11-stable (1838235 2019-12-03)

@calebcartwright
Copy link
Member

@vss96 could you share a bit more about your code (preferrably a snippet with at least the mod import) and/or provide a minimal repo that can be used to reproduce the behavior?

Also, what OS are you using when you encounter the error?

@vss96
Copy link
Author

vss96 commented Mar 11, 2020

@calebcartwright I'm using mac os right now. The file structure looks something like this.
image
Snippet from main.rs for how the structs from the files are imported. scylla.rs and search.rs have structs that are being imported into main.rs for using it.

mod controllers {

    #[path = "search.rs"]
    pub mod search;
}

#[path = "drivers"]
pub mod drivers {

    #[path = "scylla.rs"]
    pub mod scylla;
}

use crate::controllers::search;
use crate::drivers::scylla::driver::Node;
use crate::drivers::scylla::ScyllaDriver;

The error that pops up: Error writing files: io error: Failed to find module driver in "drivers" None

@gilescope
Copy link

gilescope commented Mar 23, 2020

I get the same on Win10, latest nightly 1.43, but I've got a more perverse example: if you cargo fmt any code that follows kennytm's answer to this stack overflow question I think you get a repro:

https://stackoverflow.com/questions/43070430/is-there-a-way-to-use-the-cfgfeature-check-on-multiple-statements

(For me it seems CLion doen't understand cfg_if well enough yet so kennytm's workaround seems the sensible approach for now except cargo fmt barths. )

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Mar 31, 2020
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
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