Skip to content

Commit 375350a

Browse files
committed
Fix test - updating items.fn.implicit-return to be more specific
1 parent 31f840e commit 375350a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/expressions/block-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ assert_eq!(5, five);
6464
> As a control flow expression, if a block expression is the outer expression of an expression statement, the expected type is `()` unless it is followed immediately by a semicolon.
6565
6666
r[expr.block.type.diverging]
67-
A block is itself considered to be [diverging](../divergence.md) if all reachable control flow paths contain a [diverging expression](../divergence.md#r-divergence.diverging-expressions), unless that expression is a [place expression](../expressions.md#r-expr.place-value.place-memory-location) that is not read from.
67+
A block is itself considered to be [diverging](../divergence.md) if all reachable control flow paths contain a [diverging expression](../divergence.md), unless that expression is a [place expression](../expressions.md#r-expr.place-value.place-memory-location) that is not read from.
6868

6969
```rust,no_run
7070
# fn make<T>() -> T { loop {} }

src/expressions/if-expr.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ An `if` expression diverges if either the condition expression diverges or if al
7979
```rust,no_run
8080
fn diverging_condition() -> ! {
8181
// Diverges because the condition expression diverges
82-
if { loop {}; true } {
82+
if loop {} {
8383
()
8484
} else {
8585
()
86-
}
86+
};
87+
// The semicolon above is important:
88+
// The type of the `if` statement is `()`, despite being diverging.
8789
}
8890
8991
fn diverging_arms() -> ! {

src/items/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ r[items.fn.signature]
5656
Functions may declare a set of *input* [*variables*][variables] as parameters, through which the caller passes arguments into the function, and the *output* [*type*][type] of the value the function will return to its caller on completion.
5757

5858
r[items.fn.implicit-return]
59-
If the output type is not explicitly stated, it is the [unit type].
59+
If the output type is not explicitly stated, it is the [unit type]. However, if the block expression is not [diverging](../divergence.md), then the output type is instead [`!`](../types/never.md).
6060

6161
r[items.fn.fn-item-type]
6262
When referred to, a _function_ yields a first-class *value* of the corresponding zero-sized [*function item type*], which when called evaluates to a direct call to the function.

0 commit comments

Comments
 (0)