diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-07-01 13:37:02 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-07-01 19:14:27 +0200 |
| commit | 0ca7699837ff3302f65418d5bd0fc54c5fb2da4d (patch) | |
| tree | 07aa928010ae22345a23a619ba12fc29e1aadabc | |
| parent | a9e26b5ced41a3b3a18036c5ba6d44d067a34057 (diff) | |
| download | rust-0ca7699837ff3302f65418d5bd0fc54c5fb2da4d.tar.gz rust-0ca7699837ff3302f65418d5bd0fc54c5fb2da4d.zip | |
Add examples in error explanation E0267 and E0268
| -rw-r--r-- | src/librustc/diagnostics.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 68ca0eac37a..08ff692fd46 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -602,15 +602,47 @@ const Y: u32 = X; E0267: r##" This error indicates the use of a loop keyword (`break` or `continue`) inside a -closure but outside of any loop. Break and continue can be used as normal inside -closures as long as they are also contained within a loop. To halt the execution -of a closure you should instead use a return statement. +closure but outside of any loop. Erroneous code example: + +``` +let w = || { break; }; // error: `break` inside of a closure +``` + +`break` and `continue` keywords can be used as normal inside closures as long as +they are also contained within a loop. To halt the execution of a closure you +should instead use a return statement. Example: + +``` +let w = || { + for _ in 0..10 { + break; + } +}; + +w(); +``` "##, E0268: r##" This error indicates the use of a loop keyword (`break` or `continue`) outside of a loop. Without a loop to break out of or continue in, no sensible action can -be taken. +be taken. Erroneous code example: + +``` +fn some_func() { + break; // error: `break` outside of loop +} +``` + +Please verify that you are using `break` and `continue` only in loops. Example: + +``` +fn some_func() { + for _ in 0..10 { + break; // ok! + } +} +``` "##, E0271: r##" |
