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

Better error message for "[E0601]: main function not found" #44798

Closed
djc opened this issue Sep 23, 2017 · 4 comments
Closed

Better error message for "[E0601]: main function not found" #44798

djc opened this issue Sep 23, 2017 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@djc
Copy link
Contributor

djc commented Sep 23, 2017

I'm seeing this in a crate with multiple binaries defined, so one important improvement would be to name the binary that is causing the problem. Once I've figured why this error is happening incorrectly in the particular crate that I'm struggling with now, I'll probably have more suggestions.

@TimNN TimNN added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 24, 2017
@ehuss
Copy link
Contributor

ehuss commented Mar 3, 2018

See also, rust-lang/cargo#4948

@djc
Copy link
Contributor Author

djc commented Mar 9, 2018

@ehuss thanks for working on this! The changes in your PR already look this, but I don't think they fully cover the particular case I'm talking about here ("crate with multiple binaries defined") too well (that is, a crate that has a bin directory containing multiple .rs files). Am I missing something?

@ehuss
Copy link
Contributor

ehuss commented Mar 9, 2018

@djc it should work, unless I am misunderstanding your situation. From the terminology I've seen, each bin is considered a separate "crate", and a package can have multiple binary crates (rust-lang/cargo#3380). So for a package layout like this:

foo/Cargo.toml
foo/src/lib.rs
foo/main.rs
foo/bin/bin1.rs
foo/examples/ex1.rs

The corresponding errors for the three binaries would be:

  • main function not found in crate foo
  • main function not found in crate bin1
  • main function not found in crate ex1

There might be confusion (such as if you have examples with the same name as a binary, or binaries with the same name in separate packages within a workspace). That's why I proposed in the PR to add the exact path to the recommended source file where you should add a main function, but I have not heard back.

@djc
Copy link
Contributor Author

djc commented Mar 9, 2018

@ehuss, ah, awesome! In this case, I find the wording of "not found in crate" maybe a little confusing, because as far as I understand it, the intention of "crate" is usually to cover the whole thing rather than a single binary included in it.

kennytm added a commit to kennytm/rust that referenced this issue Mar 15, 2018
…tebank

Add crate name to "main function not found" error message.

Fixes rust-lang#44798 and rust-lang/cargo#4948.

I was wondering if it might be cleaner to update the ui tests to add a simple `fn main() {}` for the unrelated tests.  Let me know if you would prefer that.
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.
Projects
None yet
Development

No branches or pull requests

3 participants