-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
A-diagnosticsArea: Error and warning messages generated by Cargo itself.Area: Error and warning messages generated by Cargo itself.S-needs-team-inputStatus: Needs input from team on whether/how to proceed.Status: Needs input from team on whether/how to proceed.
Description
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
- Create a package with the following Cargo.toml:
[package]
name = "example"
version = "0.1.0"
edition = "2018"
[dependencies]
[[bin]]
name = "foo"
path = "src/foo.rs"
-
In
src/lib.rs
addmod foo;
-
In the file
src/foo.rs
add:
mod bar;
pub fn main() {
dbg!("Hello");
}
- Create the file
src/foo/bar.rs
- Run
cargo build
This results in the following error:
error[E0583]: file not found for module `bar`
--> src/foo.rs:1:5
|
1 | mod bar;
| ^^^
|
= help: name the file either bar.rs or bar/mod.rs inside the directory "src"
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)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Error and warning messages generated by Cargo itself.Area: Error and warning messages generated by Cargo itself.S-needs-team-inputStatus: Needs input from team on whether/how to proceed.Status: Needs input from team on whether/how to proceed.