Description
openedon Nov 22, 2022
Assume the following file structure:
src
bin
foo.rs
bar
baz.rs
bar.rs
main.rs
where bar.rs
has a mod baz;
in it.
When doing
mod bar;
in main.rs
, everything works like expected. The bar
module is loaded from bar.rs
and its baz
module gets loaded from bar/baz.rs
. Smooth sailing.
Now try adding
#[path = "../bar.rs"]
mod bar;
to bin/foo.rs
. What I expected was that this would behave exactly identical to mod bar
in main.rs
; after all, I've just changed the implicit location of bar.rs
to an explicit one.
Instead, this happens:
error[E0583]: file not found for module `baz`
--> src\bin\..\bar.rs:1:1
|
1 | mod baz;
| ^^^^^^^^
|
= help: to create the module `baz`, create file "src\bin\..\baz.rs" or "src\bin\..\baz\mod.rs"
For more information about this error, try `rustc --explain E0583`.
Why is it looking for src\bin\..\baz.rs
? It should be looking for src\bin\..\bar\baz.rs
, since bar.rs
is not a root module like lib.rs
or main.rs
, nor is it a mod.rs
file.
If this behavior is expected, it's not very well documented, I certainly couldn't find anything explaining this behavior in the documentation.
Meta
rustc --version --verbose
:
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-pc-windows-msvc
release: 1.65.0
LLVM version: 15.0.0