-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
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. |
In general, yes, I prefer to add an empty 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? |
I'm not entirely certain which situations --- 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:
|
@ehuss that seems like what I had in mind. Go ahead and add it to the PR. r=me once it's done. |
02f46bb
to
ab4161f
Compare
Thanks @estebank, I have updated it with the new text, updated the tests as discussed, and added a specific test for E0601. |
src/librustc/middle/entry.rs
Outdated
@@ -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())); |
There was a problem hiding this comment.
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 `{}`
src/librustc/middle/entry.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
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 `{}`
@ehuss nice PR =) left a few nits of my own |
Updated, thanks @nikomatsakis! |
@bors r+ rollup |
📌 Commit 2c07c2d has been approved by |
☔ The latest upstream changes (presumably #48684) made this pull request unmergeable. Please resolve the merge conflicts. |
2c07c2d
to
2f1b34c
Compare
@bors r+ |
📌 Commit 5257275 has been approved by |
…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.
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.