@@ -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
14498Extern functions are part of Rust's foreign function interface, providing the
@@ -169,4 +123,4 @@ As non-Rust calling conventions do not support unwinding, unwinding past the end
169123of an extern function will cause the process to abort. In LLVM, this is
170124implemented by executing an illegal instruction.
171125
172- [ external blocks ] : items/external-blocks.html
126+ [ external blocks ] : items/external-blocks.html
0 commit comments