Keywords

Rust divides keywords into three categories:

Strict keywords

Strict keywords can only be used in their correct contexts. They cannot be used as the names of:

@root STRICT_KEYWORDS ->
      `_`
    | `as`
    | `async`
    | `await`
    | `break`
    | `const`
    | `continue`
    | `crate`
    | `dyn`
    | `else`
    | `enum`
    | `extern`
    | `false`
    | `fn`
    | `for`
    | `if`
    | `impl`
    | `in`
    | `let`
    | `loop`
    | `match`
    | `mod`
    | `move`
    | `mut`
    | `pub`
    | `ref`
    | `return`
    | `self`
    | `Self`
    | `static`
    | `struct`
    | `super`
    | `trait`
    | `true`
    | `type`
    | `unsafe`
    | `use`
    | `where`
    | `while`

2018 Edition differences

The following keywords were added in the 2018 edition:

  • async
  • await
  • dyn

Reserved keywords

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

@root RESERVED_KEYWORDS ->
      `abstract`
    | `become`
    | `box`
    | `do`
    | `final`
    | `gen`
    | `macro`
    | `override`
    | `priv`
    | `try`
    | `typeof`
    | `unsized`
    | `virtual`
    | `yield`

2018 Edition differences

The try keyword was added as a reserved keyword in the 2018 edition.

2024 Edition differences

The gen keyword was added as a reserved keyword in the 2024 edition.

Weak keywords

Weak keywords have special meaning only in certain contexts. For example, it is possible to declare a variable or method with the name union.

@root WEAK_KEYWORDS ->
      `'static`
    | `macro_rules`
    | `raw`
    | `safe`
    | `union`

2018 Edition differences

In the 2015 edition, dyn is a keyword when used in a type position followed by a path that does not start with :: or <, a lifetime, a question mark, a for keyword or an opening parenthesis.

Beginning in the 2018 edition, dyn has been promoted to a strict keyword.