-
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
Suggest removing value from break
when invalid
#47829
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -3,6 +3,10 @@ error[E0571]: `break` with value from a `for` loop | |||
| | |||
22 | break 22 //~ ERROR `break` with value from a `for` loop | |||
| ^^^^^^^^ can only break with a value inside `loop` | |||
help: instead, use `break` on its own without a value inside this `for` loop | |||
| | |||
22 | break //~ ERROR `break` with value from a `for` loop |
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 second "by example" version of the error doesn't seem like it's providing the user with additional information. Would it be possible to change this PR to just add the additional help
message, without the break
-only example?
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 find that when suggesting removal of text, the inline suggestion style lends itself to confusion more easily. What do you think?
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 find this particular line is confusing-- I don't think it adds new information, the ERROR
pattern on it is misleading since there would be no error in this case (since it's the corrected code):
22 | break //~ ERROR `break` with value from a `for` loop
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.
But that's just a comment, as far as rustc
is concerned. If I change the test file to have that comment one line below, it would look like this:
error[E0571]: `break` with value from a `for` loop
--> $DIR/loop-break-value-no-repeat.rs:22:9
|
22 | break 22
| ^^^^^^^^ can only break with a value inside `loop`
help: instead, use `break` on its own without a value inside this `for` loop
|
22 | break
| ^^^^^
instead of
error[E0571]: `break` with value from a `for` loop
--> $DIR/loop-break-value-no-repeat.rs:22:9
|
22 | break 22
| ^^^^^^^^
| |
| can only break with a value inside `loop`
| help: use `break` without a value: `break`
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.
Ah, okay. I personally still prefer something like this:
error[E0571]: `break` with value from a `for` loop
--> $DIR/loop-break-value-no-repeat.rs:22:9
|
22 | break 22
| ^^^^^^^^
| |
| can only break with a value inside `loop`
| help: use `break` without a value inside this `for` loop
But I'll defer to your judgement.
r=me with nit fixed. |
@bors r=cramertj rollup We can change this to inline afterwards. I'm thinking that the current output style could be reserved for |
📌 Commit b7437c5 has been approved by |
…uggest removing value from `break` when invalid When attempting to use `break` with a value in a type of loop where it'd be invalid (any non-`loop`), suggest using `break` on its own. Close rust-lang#34359.
When attempting to use
break
with a value in a type of loop where it'd be invalid (any non-loop
), suggest usingbreak
on its own.Close #34359.