Skip to content

Commit 7a4edcd

Browse files
committed
Document multiple return types in main
1 parent 5d4ff25 commit 7a4edcd

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/crates-and-source-files.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
> UTF8BOM : `\uFEFF`
1212
> SHEBANG : `#!` ~[`[` `\n`] ~`\n`<sup>*</sup>
1313
14-
Although Rust, like any other language, can be implemented by an interpreter as
15-
well as a compiler, the only existing implementation is a compiler,
16-
and the language has
17-
always been designed to be compiled. For these reasons, this section assumes a
18-
compiler.
14+
15+
> Note: Although Rust, like any other language, can be implemented by an
16+
> interpreter as well as a compiler, the only existing implementation is a
17+
> compiler,and the language has always been designed to be compiled. For these
18+
> reasons, this section assumes a compiler.
1919
2020
Rust's semantics obey a *phase distinction* between compile-time and
2121
run-time.[^phase-distinction] Semantic rules that have a *static
@@ -66,9 +66,17 @@ apply to the crate as a whole.
6666
#![warn(non_camel_case_types)]
6767
```
6868

69-
A crate that contains a `main` function can be compiled to an executable. If a
70-
`main` function is present, its return type must be `()`
71-
("[unit]") and it must take no arguments.
69+
A crate that contains a `main` [function] can be compiled to an executable. If a
70+
`main` function is present, it must take no arguments and its return type must
71+
be one of the following:
72+
73+
* `()`
74+
* `bool`
75+
* `i32`
76+
* `Result<T, E> where T: on this list, E: Error`
77+
78+
> Note: The implementation of which return types is allowed is the unstable
79+
> [`Termination`] trait.
7280
7381
The optional [_UTF8 byte order mark_] (UTF8BOM production) indicates that the
7482
file is encoded in UTF8. It can only occur at the beginning of the file and
@@ -98,9 +106,11 @@ fn main() {
98106

99107
[module]: items/modules.html
100108
[module path]: paths.html
101-
[attributes]: items-and-attributes.html
109+
[attributes]: attributes.html
102110
[unit]: types.html#tuple-types
103111
[_InnerAttribute_]: attributes.html
104112
[_Item_]: items.html
105113
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix)
106114
[_utf8 byte order mark_]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
115+
[function]: items/functions.html
116+
[`Termination`]: ../std/process/trait.Termination.html

0 commit comments

Comments
 (0)