-
Notifications
You must be signed in to change notification settings - Fork 535
Document restrictions of the main function #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,11 @@ | |
> UTF8BOM : `\uFEFF` | ||
> SHEBANG : `#!` ~[`[` `\n`] ~`\n`<sup>*</sup> | ||
|
||
Although Rust, like any other language, can be implemented by an interpreter as | ||
well as a compiler, the only existing implementation is a compiler, | ||
and the language has | ||
always been designed to be compiled. For these reasons, this section assumes a | ||
compiler. | ||
|
||
> Note: Although Rust, like any other language, can be implemented by an | ||
> interpreter as well as a compiler, the only existing implementation is a | ||
> compiler,and the language has always been designed to be compiled. For these | ||
> reasons, this section assumes a compiler. | ||
|
||
Rust's semantics obey a *phase distinction* between compile-time and | ||
run-time.[^phase-distinction] Semantic rules that have a *static | ||
|
@@ -66,9 +66,19 @@ apply to the crate as a whole. | |
#![warn(non_camel_case_types)] | ||
``` | ||
|
||
A crate that contains a `main` function can be compiled to an executable. If a | ||
`main` function is present, its return type must be `()` | ||
("[unit]") and it must take no arguments. | ||
A crate that contains a `main` [function] can be compiled to an executable. If a | ||
`main` function is present, it must take no arguments, must not declare any | ||
[trait or lifetime bounds], must not have any [where clauses], and its return | ||
type must be one of the following: | ||
|
||
* `()` | ||
* `bool` | ||
* `i32` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bool and i32 don't implement Termination at the moment. |
||
<!-- `!` --> | ||
* `Result<T, E> where T: on this list, E: Error` | ||
|
||
> Note: The implementation of which return types is allowed is the unstable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are allowed. |
||
> [`Termination`] trait. | ||
|
||
The optional [_UTF8 byte order mark_] (UTF8BOM production) indicates that the | ||
file is encoded in UTF8. It can only occur at the beginning of the file and | ||
|
@@ -98,9 +108,13 @@ fn main() { | |
|
||
[module]: items/modules.html | ||
[module path]: paths.html | ||
[attributes]: items-and-attributes.html | ||
[attributes]: attributes.html | ||
[unit]: types.html#tuple-types | ||
[_InnerAttribute_]: attributes.html | ||
[_Item_]: items.html | ||
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix) | ||
[_utf8 byte order mark_]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8 | ||
[function]: items/functions.html | ||
[`Termination`]: ../std/process/trait.Termination.html | ||
[where clause]: items/where-clauses.html | ||
[trait or lifetime bounds]: trait-bounds.html |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not from this PR, but binary crates are determined by the crate type, not the presence of
main
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot on that page I don't like, but I wanted to keep this change self-contained.