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

E0583: Improve error message to help with use vs mod confusion #69492

Closed
kornelski opened this issue Feb 26, 2020 · 4 comments · Fixed by #116992
Closed

E0583: Improve error message to help with use vs mod confusion #69492

kornelski opened this issue Feb 26, 2020 · 4 comments · Fixed by #116992
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kornelski
Copy link
Contributor

kornelski commented Feb 26, 2020

Feedback from a user forum thread. This code:

mod foo {
}

mod bar {
    mod foo;
}

currently suggests:

= help: name the file either foo.rs or foo/mod.rs inside the directory "src/bar"

This is awkwardly worded. It doesn't clearly explain that this syntax creates a new module. It doesn't guess that the user may have meant use crate::foo.

I suggest:

  1. Improve wording of the message. "To create a new module crate::bar::foo, create "src/bar/foo.rs" file" (to keep it simple, without also suggesting 2015-edition path).

  2. If there already is a module with that name, suggest use instead.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 26, 2020
@kornelski
Copy link
Contributor Author

I couldn't find a way to get path to the current module, or names of already parsed modules.

It seems that this info isn't explicitly tracked at such an early stage in the parsing, and I'm not sure if it's OK to add it.

@estebank
Copy link
Contributor

I'm unambiguously in favor of 1 and tepidly positive about 2. The implementation of 2 might be difficult that early on.

kornelski added a commit to kornelski/rust that referenced this issue Mar 1, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 5, 2020
Make error message clearer about creating new module

This is a partial improvement for rust-lang#69492
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 5, 2020
Make error message clearer about creating new module

This is a partial improvement for rust-lang#69492
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 16, 2020
Make error message clearer about creating new module

This is a partial improvement for rust-lang#69492
@estebank
Copy link
Contributor

Current output:

error[E0583]: file not found for module `foo`
 --> src/lib.rs:5:5
  |
5 |     mod foo;
  |     ^^^^^^^^
  |
  = help: to create the module `foo`, create file "src/bar/foo.rs" or "src/bar/foo/mod.rs"

estebank added a commit to estebank/rust that referenced this issue Oct 20, 2023
Newcomers might get confused that `mod` is the only way of defining
scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
@estebank
Copy link
Contributor

@kornelski resurrected your change under #116992

estebank added a commit to estebank/rust that referenced this issue Oct 20, 2023
Newcomers might get confused that `mod` is the only way of defining
scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
estebank added a commit to estebank/rust that referenced this issue Oct 20, 2023
Newcomers might get confused that `mod` is the only way of defining
scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 20, 2023
Mention the syntax for `use` on `mod foo;` if `foo` doesn't exist

Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 21, 2023
Mention the syntax for `use` on `mod foo;` if `foo` doesn't exist

Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
@bors bors closed this as completed in 2cca435 Oct 21, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 21, 2023
Rollup merge of rust-lang#116992 - estebank:issue-69492, r=oli-obk

Mention the syntax for `use` on `mod foo;` if `foo` doesn't exist

Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`.

Fix rust-lang#69492.
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants