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

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

Merged
merged 5 commits into from
Mar 16, 2018

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Mar 3, 2018

Fixes #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.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 3, 2018
@estebank
Copy link
Contributor

estebank commented Mar 3, 2018

In general, yes, I prefer to add an empty main instead.

As for the change, I think there'd be value in having the path of the file we're looking for the method in a note as well, but don't know how hard that'd be to add. What do you think @ehuss?

@ehuss
Copy link
Contributor Author

ehuss commented Mar 3, 2018

I'm not entirely certain which situations local_crate_source_file is None. What do you think about something like this:

--- a/src/librustc/middle/entry.rs
+++ b/src/librustc/middle/entry.rs
@@ -178,6 +178,9 @@ fn configure_main(this: &mut EntryContext, crate_name: &str) {
             err.emit();
             this.session.abort_if_errors();
         } else {
+            if let Some(ref filename) = this.session.local_crate_source_file {
+                err.note(&format!("consider adding a main function to {}", filename.display()));
+            }
             if this.session.teach(&err.get_code().unwrap()) {
                 err.note("If you don't know the basics of Rust, you can go look to the Rust Book \
                           to get started: https://doc.rust-lang.org/book/");

which would render as:

error[E0601]: main function not found in crate bin_no_main
  |
  = note: consider adding a main function to main-not-found/src/bin/bin_no_main.rs

error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0601"

@pietroalbini
Copy link
Member

Ping from triage! Can @estebank or someone from @rust-lang/compiler reply to @ehuss comment?

@estebank
Copy link
Contributor

@ehuss that seems like what I had in mind. Go ahead and add it to the PR. r=me once it's done.

@ehuss
Copy link
Contributor Author

ehuss commented Mar 13, 2018

Thanks @estebank, I have updated it with the new text, updated the tests as discussed, and added a specific test for E0601.

@@ -175,6 +178,9 @@ fn configure_main(this: &mut EntryContext) {
err.emit();
this.session.abort_if_errors();
} else {
if let Some(ref filename) = this.session.local_crate_source_file {
err.note(&format!("consider adding a main function to {}", filename.display()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can this be using backticks? e.g.,

`main` function to `{}`

@@ -162,7 +164,8 @@ fn configure_main(this: &mut EntryContext) {
this.session.entry_type.set(Some(config::EntryMain));
} else {
// No main function
let mut err = struct_err!(this.session, E0601, "main function not found");
let mut err = struct_err!(this.session, E0601,
"main function not found in crate {}", crate_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: backticks please :)

`main` function not found in crate `{}`

@nikomatsakis
Copy link
Contributor

@ehuss nice PR =) left a few nits of my own

@ehuss
Copy link
Contributor Author

ehuss commented Mar 13, 2018

Updated, thanks @nikomatsakis!

@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 13, 2018

📌 Commit 2c07c2d has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 13, 2018
@bors
Copy link
Contributor

bors commented Mar 14, 2018

☔ The latest upstream changes (presumably #48684) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 14, 2018
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 14, 2018

📌 Commit 5257275 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 14, 2018
kennytm added a commit to kennytm/rust that referenced this pull request 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
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants