-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Spurious "error[E0583]: file not found for module" error. #7730
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
Comments
|
@ehuss It leads to an error reguardless of location. Let me run through this as a script.
Output is:
Think: "Ok great, I'll just create foo/bar.rs because that is missing...
Output is:
Think: "Humm, I guess bar doesn't go in the foo subdirectory, but rather goes directly in src. It's odd that the earlier error told me to put it in the foo subdirectory." run:
Think: "Where the fuck does it go?! I just tried both places!" |
Ah, I see how that is confusing. I would recommend avoiding mounting the same module between crates and overriding the default project layout (which can help avoid this kind of confusion). To clarify, there are two crates trying to define a module with the same name in two different places. That is:
Typically binaries go in |
Is it feasible to detect this situation and give a better error? As it stands results in a very confusing situation, that is easily reachable by starting with a library and then deciding to add a "main" in one of your files and following the instructions for how to add a binary target for cargo. |
I think it'll be difficult to detect, especially without false positives, since there might be legitimate cases of using the same file in multiple crates. It might be possible to detect if a lib loads the root source file on a binary, and produce a warning. |
having the mod file to list all is also weird, are there any not to be included? why are they there in the first place. |
Problem
When a project has a binary target, and in the same file declares a module, the compilation will fail with a
error[E0583]: file not found for module
even though the file exists.Steps
In
src/lib.rs
addmod foo;
In the file
src/foo.rs
add:src/foo/bar.rs
cargo build
This results in the following error:
Which is very confusing because such a file exists.
Notes
Using stable channel.
Output of
cargo version
: cargo 1.40.0 (bc8e4c8 2019-11-22)The text was updated successfully, but these errors were encountered: