@@ -93,52 +93,6 @@ sufficient context to determine the type parameters. For example,
93
93
94
94
[ path ] : paths.html
95
95
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
-
142
96
## Extern functions
143
97
144
98
Extern functions are part of Rust's foreign function interface, providing the
0 commit comments