File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -223,12 +223,45 @@ To fix this, add a label specifying which loop is being broken out of:
223
223
```
224
224
'foo: while break 'foo {}
225
225
```
226
+ "## ,
227
+
228
+ E0571 : r##"
229
+ A `break` statement with an argument appeared in a non-`loop` loop.
230
+
231
+ Example of erroneous code:
232
+
233
+ ```compile_fail,E0571
234
+ # let mut i = 1;
235
+ # fn satisfied(n: usize) -> bool { n % 23 == 0 }
236
+ let result = while true {
237
+ if satisfied(i) {
238
+ break 2*i; // error: `break` with value from a `while` loop
239
+ }
240
+ i += 1;
241
+ };
242
+ ```
243
+
244
+ The `break` statement can take an argument (which will be the value of the loop
245
+ expression if the `break` statement is executed) in `loop` loops, but not
246
+ `for`, `while`, or `while let` loops.
247
+
248
+ Make sure `break value;` statements only occur in `loop` loops:
249
+
250
+ ```
251
+ # let mut i = 1;
252
+ # fn satisfied(n: usize) -> bool { n % 23 == 0 }
253
+ let result = loop { // ok!
254
+ if satisfied(i) {
255
+ break 2*i;
256
+ }
257
+ i += 1;
258
+ };
259
+ ```
226
260
"##
227
261
}
228
262
229
263
register_diagnostics ! {
230
264
E0226 , // only a single explicit lifetime bound is permitted
231
265
E0472 , // asm! is unsupported on this target
232
266
E0561 , // patterns aren't allowed in function pointer types
233
- E0571 , // `break` with a value in a non-`loop`-loop
234
267
}
You can’t perform that action at this time.
0 commit comments