Skip to content

Commit e713055

Browse files
Merge pull request #345 from Havvy/try-in-main
Document restrictions of the main function
2 parents 2603245 + 3348d21 commit e713055

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/crates-and-source-files.md

Lines changed: 21 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, must not declare any
71+
[trait or lifetime bounds], must not have any [where clauses], and its return
72+
type must be one of the following:
73+
74+
* `()`
75+
<!-- * `!` -->
76+
* `Result<T, E> where T: on this list, E: Error`
77+
78+
> Note: The implementation of which return types are allowed is determined by
79+
> the unstable [`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,13 @@ 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
117+
[where clause]: items/where-clauses.html
118+
[trait or lifetime bounds]: trait-bounds.html

0 commit comments

Comments
 (0)