-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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 diagnostics to "while loop" and "for loop" that note that it is always determined that it migh t iterate zero times. #126510
base: master
Are you sure you want to change the base?
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
loop_span, | ||
format!("It is determined that this might iterate zero times, regardless of the {loop_header}.") | ||
); | ||
err.span_help(loop_span, "If you are assuming that it will iterate more than once, consider using a `loop` expression instead."); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…lways determined that it might iterate zero times.
5385719
to
3b159a8
Compare
LL + /* `bool` value */ | ||
| | ||
|
||
error: aborting due to 1 previous error |
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.
A number of issues here.
- Error messages don't start with an upper-case letter, and don't end with a '.'.
- There is a lot of repetition here. The
note
and the followinghelp
both print the loop condition. The two could be merged. I am also not sure if the condition needs to be printed, given that the loop is printed above anyway. - "It is determined" is too wordy, something like "this loop might iterate zero times" would be better.
But there are bigger concerns, which I will discuss below.
There's a big problem here: the error messages mentioned in #116572 have since changed greatly. E.g. for the first example in that issue it now just says "
But because the message has changed so much, there is now no mention of zero elements, so this PR isn't following that suggestion. #122561 was also complaining about the old message, and #123125 was the PR that changed the message in order to fix #122561. So I think this PR is not actually needed, and #116572 can now be closed. But I will ask Esteban, who reviewed #123125, for a second opinion, because this is a complicated situation and is stretching my expertise on error messages to breaking point. r? @estebank |
close #116572
When a user writes a loop expression as a tail expression, which has a loop header always executed, and which contains return expressions like this,
this,
or this,
they may be misundrestanding that it evaluate to not a unit type but un argument of the return expression.
This PR adds diagnositics which help clearing such misundrestanding.