Skip to content

Commit 6a42f5d

Browse files
authored
Merge pull request #823 from ehuss/shebang-restriction
Document shebang restriction.
2 parents 0ea7bc4 + 277587a commit 6a42f5d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/crates-and-source-files.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
> **<sup>Lexer</sup>**\
1111
> UTF8BOM : `\uFEFF`\
12-
> SHEBANG : `#!` ~[`[` `\n`] ~`\n`<sup>\*</sup>
12+
> SHEBANG : `#!` \~`\n`<sup>\+</sup>[](#shebang)
1313
1414

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

68+
## Byte order mark
69+
6870
The optional [_UTF8 byte order mark_] (UTF8BOM production) indicates that the
6971
file is encoded in UTF8. It can only occur at the beginning of the file and
7072
is ignored by the compiler.
7173

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

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

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

0 commit comments

Comments
 (0)