Skip to content

Commit b7437c5

Browse files
committed
Suggest removing value from break when invalid
1 parent bacb5c5 commit b7437c5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/librustc_passes/loops.rs

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
119119
kind.name())
120120
.span_label(e.span,
121121
"can only break with a value inside `loop`")
122+
.span_suggestion(e.span,
123+
&format!("instead, use `break` on its own \
124+
without a value inside this `{}` loop",
125+
kind.name()),
126+
"break".to_string())
122127
.emit();
123128
}
124129
}

src/test/ui/loop-break-value-no-repeat.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ error[E0571]: `break` with value from a `for` loop
33
|
44
22 | break 22 //~ ERROR `break` with value from a `for` loop
55
| ^^^^^^^^ can only break with a value inside `loop`
6+
help: instead, use `break` on its own without a value inside this `for` loop
7+
|
8+
22 | break //~ ERROR `break` with value from a `for` loop
9+
| ^^^^^
610

711
error: aborting due to previous error
812

0 commit comments

Comments
 (0)