Closed
Description
Rustfmt seems to be unable to deal with sub-modules in directories without mod.rs:
- https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
- [RFC 2126] permit
foo.rs
orfoo/mod.rs
to support submodules likefoo/bar.rs
rust#45385 - Tracking issue for RFC 2126: Clarify and streamline paths and visibility rust#44660
I'm getting rustfmt
errors for my project:
$ rustup show
Default host: x86_64-apple-darwin
installed toolchains
--------------------
stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin
active toolchain
----------------
stable-x86_64-apple-darwin (default)
rustc 1.34.0 (91856ed52 2019-04-10)
$ rustfmt --version
rustfmt 1.0.3-stable (d6829d62 2019-02-14)
$ cargo run
Compiling rustfmttest v0.1.0 (/Users/sethwm/Desktop/rustfmttest)
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
Running `target/debug/rustfmttest`
Hello, world!
HELLO WORLD 1
Hello World 2
$ rustfmt src/foo.rs
error[E0583]: file not found for module `bar`
--> /Users/sethwm/Desktop/rustfmttest/src/foo.rs:1:9
|
1 | pub mod bar;
| ^^^
|
= help: name the file either bar.rs or bar/mod.rs inside the directory "/Users/sethwm/Desktop/rustfmttest/src"
Here is the source:
$ find . | grep -v git
.
./Cargo.lock
./Cargo.toml
./src
./src/foo
./src/foo/bar.rs
./src/foo.rs
./src/main.rs
$ cat src/main.rs
mod foo;
use crate::foo::bar::*;
use crate::foo::*;
fn main() {
println!("Hello, world!");
foo_fn();
bar_fn();
}
$ cat src/foo.rs
pub mod bar;
pub fn foo_fn() {
println!("HELLO WORLD 1");
}
$ cat src/foo/bar.rs
pub fn bar_fn() {
println!("Hello World 2");
}