Skip to content

Commit 588eb6d

Browse files
authored
Merge pull request #254 from matthewjasper/keywords
Revise keywords page
2 parents 86b7c82 + 66af01c commit 588eb6d

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

src/keywords.md

+43-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
# Keywords
22

33
Rust divides keywords into three categories:
4-
- [strict](#strict-keywords)
5-
- [weak](#weak-keywords)
6-
- [reserved](#reserved-keywords)
4+
5+
* [strict](#strict-keywords)
6+
* [reserved](#reserved-keywords)
7+
* [weak](#weak-keywords)
78

89
## Strict keywords
910

10-
These keywords can only be used in their correct contexts. For example, it is
11-
not allowed to declare a variable with name `struct`.
11+
These keywords can only be used in their correct contexts. They cannnot
12+
be used as the names of:
13+
14+
* [Items]
15+
* [Variables] and function parameters
16+
* Fields and [variants]
17+
* [Type parameters]
18+
* Lifetime parameters or [loop labels]
19+
* [Macros] or [attributes]
20+
* [Macro placeholders]
21+
* [Crates]
1222

1323
> **<sup>Lexer:<sup>**
1424
> KW_AS : `as`
15-
> KW_BOX : `box`
1625
> KW_BREAK : `break`
1726
> KW_CONST : `const`
1827
> KW_CONTINUE : `continue`
@@ -48,27 +57,18 @@ not allowed to declare a variable with name `struct`.
4857
> KW_WHERE : `where`
4958
> KW_WHILE : `while`
5059
51-
## Weak keywords
52-
53-
These keywords have special meaning only in certain contexts. For example,
54-
it is possible to declare a variable or method with the name `union`.
55-
56-
> **<sup>Lexer</sup>**
57-
> KW_CATCH : `catch`
58-
> KW_DEFAULT : `default`
59-
> KW_UNION : `union`
60-
> KW_STATICLIFETIME : `'static`
61-
6260
## Reserved keywords
6361

64-
These keywords aren't used yet, but they are reserved for future use.
65-
The reasoning behind this is to make current programs forward compatible with
66-
future versions of Rust by forbidding them to use these keywords.
62+
These keywords aren't used yet, but they are reserved for future use. They have
63+
the same restrictions as strict keywords. The reasoning behind this is to make
64+
current programs forward compatible with future versions of Rust by forbidding
65+
them to use these keywords.
6766

6867
> **<sup>Lexer</sup>**
6968
> KW_ABSTRACT : `abstract`
7069
> KW_ALIGNOF : `alignof`
7170
> KW_BECOME : `become`
71+
> KW_BOX : `box`
7272
> KW_DO : `do`
7373
> KW_FINAL : `final`
7474
> KW_MACRO : `macro`
@@ -82,3 +82,26 @@ future versions of Rust by forbidding them to use these keywords.
8282
> KW_UNSIZED : `unsized`
8383
> KW_VIRTUAL : `virtual`
8484
> KW_YIELD : `yield`
85+
86+
## Weak keywords
87+
88+
These keywords have special meaning only in certain contexts. For example, it
89+
is possible to declare a variable or method with the name `union`.
90+
91+
* `union` is used to declare a [union]
92+
* `'static` is used for a static lifetime
93+
94+
> **<sup>Lexer</sup>**
95+
> KW_UNION : `union`
96+
> KW_STATICLIFETIME : `'static`
97+
98+
[items]: items.html
99+
[Variables]: variables.html
100+
[Type parameters]: types.html#type-parameters
101+
[loop labels]: expressions/loop-expr.html#loop-labels
102+
[Macros]: macros.html
103+
[attributes]: attributes.html
104+
[Macro placholders]: macros-by-example.html
105+
[Crates]: crates-and-source-files.html
106+
[union]: items/unions.html
107+
[variants]: items/enumerations.html

0 commit comments

Comments
 (0)