-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
suggest return type for main() #62384
Conversation
This adds a suggestion for main() methods with default () return if the resulting expression has a type that implements `std::process::Termination`. This fixes rust-lang#61277.
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.
Can you please also add tests to exercise this behavior?
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.
LGTM, please add tests.
err.span_suggestion( | ||
span, | ||
"try adding a return type", | ||
format!("-> {} ", ret_ty), |
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.
I think the whitespace in the code suggestion might be subtly wrong. I believe this should be " -> {} ", but without the
stderr` test output I can't say for sure.
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.
I just added a UI test, but the suggestion doesn't appear. Any idea why?
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.
I'm not sure. Could you add some debug
statements to verify the contents of fn_decl.output
, found.is_suggestable()
, can_suggest
, expected
and ret_ty
?
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.
Sure thing.
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
|
It appears that the
|
I see. The problem is that |
Thanks, you're a hero! |
@llogiq the reason the suggestion doesn't trigger is because the found type references
I see two options: 1) modify the machinery in This later suggestion would end up causing an error like the following though:
Maybe suggesting replacing all the |
Another pattern that would be interesting to support is
|
Ping from triage. @llogiq any updates on this? |
I'm afraid I have a lot of code reading and understanding to do before I can implement @estebank's proposal. If you like, you can close the PR, and I'll reopen it when I have something working. |
Ping from triage: @llogiq, I'll close this PR to keep things tidy. But don't worry, you can re-open this if you find a time to read and understand code to implement, we'll be happy to review it again! Thanks for taking the time to contribute. |
This adds a suggestion for
main()
methods with default()
return if the resulting expression has a type that implementsstd::process::Termination
.This fixes #61277.
r? @estebank