Skip to content

rustfmt fails on sub-modules in directory without mod.rs #3516

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rusty-objects opened this issue Apr 17, 2019 · 1 comment
Closed

rustfmt fails on sub-modules in directory without mod.rs #3516

rusty-objects opened this issue Apr 17, 2019 · 1 comment

Comments

@rusty-objects
Copy link

Rustfmt seems to be unable to deal with sub-modules in directories without mod.rs:

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");
}

@topecongiro
Copy link
Contributor

This is fixed in 1.2.0, but has not reached the stable release yet.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants