Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Protected names

Rust groups keywords into two categories: weak and strict.

Strict keywords

Strict keywords are keywords which can only be used in their correct contexts, which is to say they cannot be used as the names of items, variables, fields and variants, type parameters, macros or crates.

Generated files, modules, types and variables may not use strict keywords.

Keywords
asbreakconstcontinuecrateelse
enumexternfalsefnforif
implinletloopmatchmod
movemutpubrefreturnself
Selfstaticstructsupertraittrue
typeunsafeusewherewhileasync
awaitdynabstractbecomeboxdo
finalmacrooverrideprivtypeofunsized
virtualyieldtry

Strict keywords will be escaped in the generated Rust code by appending an underscore to the name, e.g. module_.

Weak keywords

Weak keywords have special meaning only in certain contexts. None of the current weak keywords affect the naming of types or variables. Thus, weak keywords are not reserved and may be freely used.

KeywordContext
unionOnly a keyword when used in a union declaration.
'staticCannot be used as a generic lifetime parameter or loop label.

For example, the following is perfectly valid Rust code:

#![allow(unused)]
fn main() {
fn union() {
    union union<'union> {
        union: &'union union<'union>
    }
}
}