-
Notifications
You must be signed in to change notification settings - Fork 13k
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
overhaul "missing main" diagnostic #79086
Conversation
err.span_suggestion( | ||
sp.shrink_to_lo(), | ||
"define a function named `main` at the crate root", | ||
String::from("fn main() {}\n"), | ||
Applicability::MaybeIncorrect, | ||
); |
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.
Another hint that would be helpful is to pass --crate-type lib
if you didn't mean for this to be a binary. I run into that a lot testing out things for rustdoc (really I want rust-lang/rust-playground#489, but in the meantime ...)
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.
Yes, a help
with this info might be warranted.
let span = MultiSpan::from_spans(visitor.non_main_fns.iter().map(|(_, sp)| *sp).collect()); | ||
err.span_help(span, "consider moving one of these function definitions to the crate root"); |
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.
This isn't being tested, is it? Found the test.
Also, I wonder if a span_label
per "non main fn
s" might look better.
The message doesn't account for a single fn
being found (use pluralize!()
).
err.span_suggestion( | ||
sp.shrink_to_lo(), | ||
"define a function named `main` at the crate root", | ||
String::from("fn main() {}\n"), | ||
Applicability::MaybeIncorrect, | ||
); |
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.
Yes, a help
with this info might be warranted.
error[E0601]: `main` function not found in crate `continue_after_missing_main` | ||
--> $DIR/continue-after-missing-main.rs:1:1 | ||
| | ||
LL | / #![allow(dead_code)] | ||
LL | | | ||
LL | | struct Tableau<'a, MP> { | ||
LL | | provider: &'a MP, | ||
... | | ||
LL | | | ||
LL | | } | ||
| |_^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs` | ||
help: define a function named `main` at the crate root |
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.
There are a couple of cases now where the main diagnostic doesn't have a primary span. We should have a span pointing to the first char at least. I wonder if it is because of the code deleted between 205 and 212.
@euclio Triage: any updates on this? |
Still on my radar. Hoping to get some time to work on this over the holidays. |
ping from triage: |
I don't know when I'll be able to return to this. Closing for now. |
This PR updates the diagnostic emitted when there is no main function at the crate root.
#[main]
attributeFixes #77968.
r? @estebank