1
1
# Keywords
2
2
3
3
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 )
7
8
8
9
## Strict keywords
9
10
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]
12
22
13
23
> ** <sup >Lexer:<sup >**
14
24
> KW_AS : ` as `
15
- > KW_BOX : ` box `
16
25
> KW_BREAK : ` break `
17
26
> KW_CONST : ` const `
18
27
> KW_CONTINUE : ` continue `
@@ -48,27 +57,18 @@ not allowed to declare a variable with name `struct`.
48
57
> KW_WHERE : ` where `
49
58
> KW_WHILE : ` while `
50
59
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
-
62
60
## Reserved keywords
63
61
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.
67
66
68
67
> ** <sup >Lexer</sup >**
69
68
> KW_ABSTRACT : ` abstract `
70
69
> KW_ALIGNOF : ` alignof `
71
70
> KW_BECOME : ` become `
71
+ > KW_BOX : ` box `
72
72
> KW_DO : ` do `
73
73
> KW_FINAL : ` final `
74
74
> KW_MACRO : ` macro `
@@ -82,3 +82,26 @@ future versions of Rust by forbidding them to use these keywords.
82
82
> KW_UNSIZED : ` unsized `
83
83
> KW_VIRTUAL : ` virtual `
84
84
> 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