2
2
3
3
> ** <sup >Syntax</sup >** \
4
4
> _ Crate_ :\
5
- >   ;  ; SHEBANG<sup >?</sup >\
6
5
>   ;  ; [ _ InnerAttribute_ ] <sup >\* </sup >\
7
6
>   ;  ; [ _ Item_ ] <sup >\* </sup >
8
7
9
- > ** <sup >Lexer</sup >** \
10
- > SHEBANG : ` #! ` \~ ` \n ` <sup >\+ </sup >[ †] ( #shebang )
11
-
12
-
13
8
> Note: Although Rust, like any other language, can be implemented by an
14
9
> interpreter as well as a compiler, the only existing implementation is a
15
10
> compiler, and the language has always been designed to be compiled. For these
@@ -51,6 +46,8 @@ that apply to the containing module, most of which influence the behavior of
51
46
the compiler. The anonymous crate module can have additional attributes that
52
47
apply to the crate as a whole.
53
48
49
+ > ** Note** : The file's contents may be preceded by a [ shebang] .
50
+
54
51
``` rust
55
52
// Specify the crate name.
56
53
#![crate_name = " projx" ]
@@ -63,28 +60,6 @@ apply to the crate as a whole.
63
60
#![warn(non_camel_case_types)]
64
61
```
65
62
66
- ## Shebang
67
-
68
- A source file can have a [ _ shebang_ ] (SHEBANG production), which indicates
69
- to the operating system what program to use to execute this file. It serves
70
- essentially to treat the source file as an executable script. The shebang
71
- can only occur at the beginning of the file.
72
- It is ignored by the compiler. For example:
73
-
74
- <!-- ignore: tests don't like shebang -->
75
- ``` rust,ignore
76
- #!/usr/bin/env rustx
77
-
78
- fn main() {
79
- println!("Hello!");
80
- }
81
- ```
82
-
83
- A restriction is imposed on the shebang syntax to avoid confusion with an
84
- [ attribute] . The ` #! ` characters must not be followed by a ` [ ` token, ignoring
85
- intervening [ comments] or [ whitespace] . If this restriction fails, then it is
86
- not treated as a shebang, but instead as the start of an attribute.
87
-
88
63
## Preludes and ` no_std `
89
64
90
65
This section has been moved to the [ Preludes chapter] ( names/preludes.md ) .
@@ -153,19 +128,17 @@ or `_` (U+005F) characters.
153
128
[ _InnerAttribute_ ] : attributes.md
154
129
[ _Item_ ] : items.md
155
130
[ _MetaNameValueStr_ ] : attributes.md#meta-item-attribute-syntax
156
- [ _shebang_ ] : https://en.wikipedia.org/wiki/Shebang_(Unix)
157
131
[ `ExitCode` ] : ../std/process/struct.ExitCode.html
158
132
[ `Infallible` ] : ../std/convert/enum.Infallible.html
159
133
[ `Termination` ] : ../std/process/trait.Termination.html
160
134
[ attribute ] : attributes.md
161
135
[ attributes ] : attributes.md
162
- [ comments ] : comments.md
163
136
[ function ] : items/functions.md
164
137
[ module ] : items/modules.md
165
138
[ module path ] : paths.md
139
+ [ shebang ] : input-format.md#shebang-removal
166
140
[ trait or lifetime bounds ] : trait-bounds.md
167
141
[ where clauses ] : items/generics.md#where-clauses
168
- [ whitespace ] : whitespace.md
169
142
170
143
<script >
171
144
(function () {
0 commit comments