Skip to content

Commit ae2211d

Browse files
committed
updates for ! type stabilisation
Remove section on diverging function since they are no longer special. Modify wording around description of `loop` accordingly. Add `!` to any coercion to list of coercions.
1 parent 1d9be09 commit ae2211d

File tree

3 files changed

+6
-52
lines changed

3 files changed

+6
-52
lines changed

src/expressions/loop-expr.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ Only `loop` supports [evaluation to non-trivial values](#break-and-loop-values).
3636
A `loop` expression repeats execution of its body continuously:
3737
`loop { println!("I live."); }`.
3838

39-
A `loop` expression without an associated `break` expression is
40-
[diverging](items/functions.html#diverging-functions), and doesn't
41-
return anything. A `loop` expression containing associated
42-
[`break` expression(s)](#break-expressions)
43-
may terminate, and must have type compatible with the value of the `break`
44-
expression(s).
39+
A `loop` expression without an associated `break` expression is diverging and
40+
so has type `!`. A `loop` expression containing associated
41+
[`break` expression(s)](#break-expressions) may terminate, and must have type
42+
compatible with the value of the `break` expression(s).
4543

4644
## Predicate loops
4745

src/items/functions.md

-46
Original file line numberDiff line numberDiff line change
@@ -93,52 +93,6 @@ sufficient context to determine the type parameters. For example,
9393

9494
[path]: paths.html
9595

96-
## Diverging functions
97-
98-
A special kind of function can be declared with a `!` character where the
99-
output type would normally be. For example:
100-
101-
```rust
102-
fn my_err(s: &str) -> ! {
103-
println!("{}", s);
104-
panic!();
105-
}
106-
```
107-
108-
We call such functions "diverging" because they never return a value to the
109-
caller. Every control path in a diverging function must end with a `panic!()`,
110-
a loop expression without an associated break expression, or a call to another
111-
diverging function on every control path. The `!` annotation does *not* denote
112-
a type.
113-
114-
It might be necessary to declare a diverging function because as mentioned
115-
previously, the typechecker checks that every control path in a function ends
116-
with a [`return`] or diverging expression. So, if `my_err` were declared
117-
without the `!` annotation, the following code would not typecheck:
118-
119-
[`return`]: expressions/return-expr.html
120-
121-
```rust
122-
# fn my_err(s: &str) -> ! { panic!() }
123-
124-
fn f(i: i32) -> i32 {
125-
if i == 42 {
126-
return 42;
127-
}
128-
else {
129-
my_err("Bad number!");
130-
}
131-
}
132-
```
133-
134-
This will not compile without the `!` annotation on `my_err`, since the `else`
135-
branch of the conditional in `f` does not return an `i32`, as required by the
136-
signature of `f`. Adding the `!` annotation to `my_err` informs the typechecker
137-
that, should control ever enter `my_err`, no further type judgments about `f`
138-
need to hold, since control will never resume in any context that relies on
139-
those judgments. Thus the return type on `f` only needs to reflect the `if`
140-
branch of the conditional.
141-
14296
## Extern functions
14397

14498
Extern functions are part of Rust's foreign function interface, providing the

src/type-coercions.md

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Coercion is allowed between the following types:
148148

149149
* Non capturing closures to `fn` pointers
150150

151+
* `!` to any `T`
152+
151153
### Unsized Coercions
152154

153155
The following coercions are called `unsized coercions`, since they

0 commit comments

Comments
 (0)