Skip to content

Commit d6e1594

Browse files
committed
Allow break values to diverge again
This reverts commit 3651781.
1 parent 894ae7c commit d6e1594

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

text/0000-loop-break-value.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Four forms of `break` will be supported:
8484
3. `break EXPR;`
8585
4. `break 'label EXPR;`
8686

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

8989
### Result type of loop
9090

@@ -118,6 +118,7 @@ This proposal changes the result type of 'loop' to `T`, where:
118118

119119
* if a loop is "broken" via `break;` or `break 'label;`, the loop's result type must be `()`
120120
* if a loop is "broken" via `break EXPR;` or `break 'label EXPR;`, `EXPR` must evaluate to type `T`
121+
* 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
121122
* if external constaint on the loop's result type exist (e.g. `let x: S = loop { ... };`), then `T` must be coercible to this type
122123

123124
It is an error if these types do not agree or if the compiler's type deduction
@@ -158,6 +159,11 @@ fn g() -> u32 {
158159
// ! coerces to u32
159160
loop {}
160161
}
162+
fn z() -> ! {
163+
loop {
164+
break panic!();
165+
}
166+
}
161167
```
162168

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

0 commit comments

Comments
 (0)