Skip to content

Commit 0ca7699

Browse files
Add examples in error explanation E0267 and E0268
1 parent a9e26b5 commit 0ca7699

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/librustc/diagnostics.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,47 @@ const Y: u32 = X;
602602

603603
E0267: r##"
604604
This error indicates the use of a loop keyword (`break` or `continue`) inside a
605-
closure but outside of any loop. Break and continue can be used as normal inside
606-
closures as long as they are also contained within a loop. To halt the execution
607-
of a closure you should instead use a return statement.
605+
closure but outside of any loop. Erroneous code example:
606+
607+
```
608+
let w = || { break; }; // error: `break` inside of a closure
609+
```
610+
611+
`break` and `continue` keywords can be used as normal inside closures as long as
612+
they are also contained within a loop. To halt the execution of a closure you
613+
should instead use a return statement. Example:
614+
615+
```
616+
let w = || {
617+
for _ in 0..10 {
618+
break;
619+
}
620+
};
621+
622+
w();
623+
```
608624
"##,
609625

610626
E0268: r##"
611627
This error indicates the use of a loop keyword (`break` or `continue`) outside
612628
of a loop. Without a loop to break out of or continue in, no sensible action can
613-
be taken.
629+
be taken. Erroneous code example:
630+
631+
```
632+
fn some_func() {
633+
break; // error: `break` outside of loop
634+
}
635+
```
636+
637+
Please verify that you are using `break` and `continue` only in loops. Example:
638+
639+
```
640+
fn some_func() {
641+
for _ in 0..10 {
642+
break; // ok!
643+
}
644+
}
645+
```
614646
"##,
615647

616648
E0271: r##"

0 commit comments

Comments
 (0)