-
Notifications
You must be signed in to change notification settings - Fork 891
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
Regression against 1.0.3: "error[E0583]: file not found for module" #3572
Comments
Note that changing to the 2018 edition for the |
A minimal working exampleCreate a rust file with a submodule declaration and a directory whose name is the same as the rust filename.
src/connection.rsmod common; |
It seems rustfmt gets confused for some reason with the `connection` subdirectory (see <rust-lang/rustfmt#3572>), which causes `cargo fmt` to fail. Let's just get switch directory and filename, for what might be a better naming convention for OS-specific tests anyway.
It seems rustfmt gets confused for some reason with the `connection` subdirectory (see <rust-lang/rustfmt#3572>), which causes `cargo fmt` to fail. Let's just get switch directory and filename, for what might be a better naming convention for OS-specific tests anyway.
I think I found a similar, likely related, error but it only fails on tests. Running
The files. // /tests/functional.rs
mod functional {
mod thing;
} // /tests/functional/thing.rs
#[test]
fn some_test() { assert!(true); } As the error suggests it uses the functional directory twice. Calling |
We're hitting this error in Mio (tokio-rs/mio#1030), is there any work around for this? |
On the original example in the OP, does adding an explicit path attribute help? I.e. in #[macro_use]
#[path = "common/mod.rs"]
mod common; |
@calebcartwright The following doesn't work (this is actual code as in tokio-rs/mio#1030). I get #[path = "functional"]
mod functional {
mod poll;
} A found a possible workaround in the following. #[path = "functional/poll.rs"]
mod poll; |
Thanks @Thomasdezeeuw. I tested adding the path with the sample repo linked in the original note, but didn't get a chance to look at the Mio codebase. Are you saying that the snippet you posted using #[path = "functional/poll.rs"]
mod poll; |
I ended up needing to write a way to complicate macro as can be seen here: https://github.com/tokio-rs/mio/blob/8abd613656c7438fc8b783f1630a9f61532b5444/tests/functional.rs. But yes that should work. I'm not familiar with the rustfmt code base, but to me it seems that rustc and rustfmt handle module paths differently when the module is not in its own directory, i.e. |
I wrote a crappy bash script that will simulate one example of this failure, just set -v -o pipefail
# Some diagnostics
cargo --version
cargo fmt --version
# Create a repo
cargo new --lib --vcs git --edition 2018 demo
cd demo
# Minimal working structure
echo "mod foo;" > src/lib.rs
touch src/foo.rs
cargo build
cargo fmt
# Cleanup target dir juuust in case
rm -r target
# Break the build
mkdir src/lib
# Cargo is still fine
cargo build
# But rustfmt ... yeah nah
cargo fmt So still failing with
The crappy part really is how an empty directory can even mess this up, which is annoying, because you don't see empty directories in |
Possibly fixed by #4194 |
With a 2015-edition crate, "cargo fmt" fails on both current beta and nightly, whereas stable works:
Note that for beta, the
--version
flag seems to be broken as well; it yields no output, althoughrustfmt --version
works:Anyway, to reproduce, you can run the following:
The text was updated successfully, but these errors were encountered: