Suggest removing value from break when invalid#47829
Conversation
|
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
| | ^^^^^^^^ 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.
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.
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.
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` loopThere was a problem hiding this comment.
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.
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` loopBut 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
breakwith a value in a type of loop where it'd be invalid (any non-loop), suggest usingbreakon its own.Close #34359.