1# Keywords 2 3Rust divides keywords into three categories: 4 5* [strict](#strict-keywords) 6* [reserved](#reserved-keywords) 7* [weak](#weak-keywords) 8 9## Strict keywords 10 11These keywords can only be used in their correct contexts. They cannot 12be 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] 22 23> **<sup>Lexer:<sup>**\ 24> KW_AS : `as`\ 25> KW_BREAK : `break`\ 26> KW_CONST : `const`\ 27> KW_CONTINUE : `continue`\ 28> KW_CRATE : `crate`\ 29> KW_ELSE : `else`\ 30> KW_ENUM : `enum`\ 31> KW_EXTERN : `extern`\ 32> KW_FALSE : `false`\ 33> KW_FN : `fn`\ 34> KW_FOR : `for`\ 35> KW_IF : `if`\ 36> KW_IMPL : `impl`\ 37> KW_IN : `in`\ 38> KW_LET : `let`\ 39> KW_LOOP : `loop`\ 40> KW_MATCH : `match`\ 41> KW_MOD : `mod`\ 42> KW_MOVE : `move`\ 43> KW_MUT : `mut`\ 44> KW_PUB : `pub`\ 45> KW_REF : `ref`\ 46> KW_RETURN : `return`\ 47> KW_SELFVALUE : `self`\ 48> KW_SELFTYPE : `Self`\ 49> KW_STATIC : `static`\ 50> KW_STRUCT : `struct`\ 51> KW_SUPER : `super`\ 52> KW_TRAIT : `trait`\ 53> KW_TRUE : `true`\ 54> KW_TYPE : `type`\ 55> KW_UNSAFE : `unsafe`\ 56> KW_USE : `use`\ 57> KW_WHERE : `where`\ 58> KW_WHILE : `while` 59 60The following keywords were added beginning in the 2018 edition. 61 62> **<sup>Lexer 2018+</sup>**\ 63> KW_ASYNC : `async`\ 64> KW_AWAIT : `await`\ 65> KW_DYN : `dyn` 66 67## Reserved keywords 68 69These keywords aren't used yet, but they are reserved for future use. They have 70the same restrictions as strict keywords. The reasoning behind this is to make 71current programs forward compatible with future versions of Rust by forbidding 72them to use these keywords. 73 74> **<sup>Lexer</sup>**\ 75> KW_ABSTRACT : `abstract`\ 76> KW_BECOME : `become`\ 77> KW_BOX : `box`\ 78> KW_DO : `do`\ 79> KW_FINAL : `final`\ 80> KW_MACRO : `macro`\ 81> KW_OVERRIDE : `override`\ 82> KW_PRIV : `priv`\ 83> KW_TYPEOF : `typeof`\ 84> KW_UNSIZED : `unsized`\ 85> KW_VIRTUAL : `virtual`\ 86> KW_YIELD : `yield` 87 88The following keywords are reserved beginning in the 2018 edition. 89 90> **<sup>Lexer 2018+</sup>**\ 91> KW_TRY : `try` 92 93## Weak keywords 94 95These keywords have special meaning only in certain contexts. For example, it 96is possible to declare a variable or method with the name `union`. 97 98* `macro_rules` is used to create custom [macros]. 99* `union` is used to declare a [union] and is only a keyword when used in a 100 union declaration. 101* `'static` is used for the static lifetime and cannot be used as a [generic 102 lifetime parameter] or [loop label] 103 104 ```compile_fail 105 // error[E0262]: invalid lifetime parameter name: `'static` 106 fn invalid_lifetime_parameter<'static>(s: &'static str) -> &'static str { s } 107 ``` 108* In the 2015 edition, [`dyn`] is a keyword when used in a type position 109 followed by a path that does not start with `::`. 110 111 Beginning in the 2018 edition, `dyn` has been promoted to a strict keyword. 112 113> **<sup>Lexer</sup>**\ 114> KW_UNION : `union`\ 115> KW_STATICLIFETIME : `'static` 116> 117> **<sup>Lexer 2015</sup>**\ 118> KW_DYN : `dyn` 119 120[items]: items.md 121[Variables]: variables.md 122[Type parameters]: types/parameters.md 123[loop labels]: expressions/loop-expr.md#loop-labels 124[Macros]: macros.md 125[attributes]: attributes.md 126[Macro placeholders]: macros-by-example.md 127[Crates]: crates-and-source-files.md 128[union]: items/unions.md 129[variants]: items/enumerations.md 130[`dyn`]: types/trait-object.md 131[loop label]: expressions/loop-expr.md#loop-labels 132[generic lifetime parameter]: items/generics.md 133