Skip to content

Commit 860573e

Browse files
committed
Reword para on diverging functions.
1 parent 012bb7d commit 860573e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

doc/rust.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,13 @@ fn f(i: int) -> int {
936936
}
937937
~~~~
938938

939-
The typechecker would complain that `f` doesn't return a value in the
940-
`else` branch. Adding the `!` annotation on `my_err` would
941-
express that `f` requires no explicit `return`, as if it returns
942-
control to the caller, it returns a value (true because it never returns
943-
control).
939+
This will not compile without the `!` annotation on `my_err`,
940+
since the `else` branch of the conditional in `f` does not return an `int`,
941+
as required by the signature of `f`.
942+
Adding the `!` annotation to `my_err` informs the typechecker that,
943+
should control ever enter `my_err`, no further type judgments about `f` need to hold,
944+
since control will never resume in any context that relies on those judgments.
945+
Thus the return type on `f` only needs to reflect the `if` branch of the conditional.
944946

945947
#### Pure functions
946948

0 commit comments

Comments
 (0)