Skip to content
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

Document shebang restriction. #823

Merged
merged 2 commits into from
Jul 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/crates-and-source-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

> **<sup>Lexer</sup>**\
> UTF8BOM : `\uFEFF`\
> SHEBANG : `#!` ~[`[` `\n`] ~`\n`<sup>\*</sup>
> SHEBANG : `#!` \~`\n`<sup>\+</sup>[†](#shebang)


> Note: Although Rust, like any other language, can be implemented by an
Expand Down Expand Up @@ -65,10 +65,14 @@ apply to the crate as a whole.
#![warn(non_camel_case_types)]
```

## Byte order mark

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
is ignored by the compiler.

## Shebang

A source file can have a [_shebang_] (SHEBANG production), which indicates
to the operating system what program to use to execute this file. It serves
essentially to treat the source file as an executable script. The shebang
Expand All @@ -84,6 +88,11 @@ fn main() {
}
```

A restriction is imposed on the shebang syntax to avoid confusion with an
[attribute]. The `#!` characters must not be followed by a `[` token, ignoring
intervening [comments] or [whitespace]. If this restriction fails, then it is
not treated as a shebang, but instead as the start of an attribute.

## Preludes and `no_std`

All crates have a *prelude* that automatically inserts names from a specific
Expand Down Expand Up @@ -166,8 +175,10 @@ or `-` (U+002D) characters.
[`std::prelude::v1`]: ../std/prelude/index.html
[attribute]: attributes.md
[attributes]: attributes.md
[comments]: comments.md
[function]: items/functions.md
[module]: items/modules.md
[module path]: paths.md
[trait or lifetime bounds]: trait-bounds.md
[where clauses]: items/generics.md#where-clauses
[whitespace]: whitespace.md