Rollup merge of #47829 - estebank:break-in-for, r=cramertj Suggest 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 #34359.

This commit is contained in:
kennytm 2018-02-02 16:29:16 +08:00
commit 0f36b2cf2e
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
2 changed files with 9 additions and 0 deletions

View File

@ -119,6 +119,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
kind.name())
.span_label(e.span,
"can only break with a value inside `loop`")
.span_suggestion(e.span,
&format!("instead, use `break` on its own \
without a value inside this `{}` loop",
kind.name()),
"break".to_string())
.emit();
}
}

View File

@ -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
| ^^^^^
error: aborting due to previous error