Skip to content
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

Misleading E0583 when attempting to compile a file that includes itself as a module #70545

Open
9999years opened this issue Mar 29, 2020 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@9999years
Copy link
Contributor

If we have any file aaa.rs and example.rs in the same directory, where example.rs contains:

mod aaa;
mod example;

Compiling example.rs with rustc example.rs gives an error about being unable to find aaa, rather than an error about example.rs importing itself as a module:

$ rustc example.rs
error[E0583]: file not found for module `aaa`
 --> example.rs:1:5
  |
1 | mod aaa;
  |     ^^^
  |
  = help: name the file either example/aaa.rs or example/aaa/mod.rs inside the directory ""

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
The error message with rustc +nightly.
error[E0583]: file not found for module `aaa`
 --> example.rs:1:1
  |
1 | mod aaa;
  | ^^^^^^^^
  |
  = help: to create the module `aaa`, create file "example/aaa.rs"

error[E0583]: file not found for module `example`
 --> example.rs:2:1
  |
2 | mod example;
  | ^^^^^^^^^^^^
  |
  = help: to create the module `example`, create file "example/example.rs"

error[E0601]: `main` function not found in crate `example`
 --> example.rs:1:1
  |
1 | / mod aaa;
2 | | mod example;
  | |____________^ consider adding a `main` function to `example.rs`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0583, E0601.
For more information about an error, try `rustc --explain E0583`.

I expected to see this happen: rustc give an error about mod example; in example.rs.

Instead, this happened: rustc gave an error about not being able to find the first import in the file relative to example.rs as a module.

The error messages are a little bit better on nightly, but still misleading.

Shell script to reproduce the issue.
#!/usr/bin/env bash
pushd "$(mktemp --directory)" > /dev/null || exit

touch aaa.rs
echo "mod aaa;" > example.rs
echo "mod example;" >> example.rs
rustc example.rs

popd > /dev/null || exit

Meta

rustc --version --verbose:

rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.42.0
LLVM version: 9.0

rustc +nightly --version --verbose:

rustc 1.44.0-nightly (1057dc97a 2020-03-20)
binary: rustc
commit-hash: 1057dc97afce39ff6a224966ece3ed438af4c1f5
commit-date: 2020-03-20
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

The error messages are the same with RUST_BACKTRACE=1 on the stable and nightly compilers.

@9999years 9999years added the C-bug Category: This is a bug. label Mar 29, 2020
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Mar 30, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants