Skip to content

Commit

Permalink
Require break expr to converge
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed May 20, 2016
1 parent ba6b0cc commit 3651781
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions text/0000-loop-break-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Four forms of `break` will be supported:
3. `break EXPR;`
4. `break 'label EXPR;`

where `'label` is the name of a loop and `EXPR` is an expression.
where `'label` is the name of a loop and `EXPR` is an converging expression.

### Result type of loop

Expand Down Expand Up @@ -88,7 +88,6 @@ This proposal changes the result type of 'loop' to `T`, where:

* if a loop is "broken" via `break;` or `break 'label;`, the loop's result type must be `()`
* if a loop is "broken" via `break EXPR;` or `break 'label EXPR;`, `EXPR` must evaluate to type `T`
* as a special case, if a loop is "broken" via `break EXPR;` or `break 'label EXPR;` where `EXPR` evaluates to type `!` (does not return), this does not place a constraint on the type of the loop
* if external constaint on the loop's result type exist (e.g. `let x: S = loop { ... };`), then `T` must be coercible to this type

It is an error if these types do not agree or if the compiler's type deduction
Expand Down Expand Up @@ -129,11 +128,6 @@ fn g() -> u32 {
// ! coerces to u32
loop {}
}
fn z() -> ! {
loop {
break panic!();
}
}
```

Example showing the equivalence of `break;` and `break ();`:
Expand Down

0 comments on commit 3651781

Please sign in to comment.