An entity is a language construct that can be referred to in some way within the source program, usually via a path. Entities include types, items, generic parameters, variable bindings, loop labels, lifetimes, fields, attributes, and lints.
A declaration is a syntactical construct that can introduce a name to refer to an entity. Entity names are valid within a scope — a region of source text where that name may be referenced.
Names are segregated into different namespaces, allowing entities in different namespaces to share the same name without conflict.
Name resolution is the compile-time process of tying paths, identifiers, and labels to entity declarations.
Access to certain names may be restricted based on their visibility.
Entities that explicitly introduce a name in the source code are:
- Module declarations
- External crate declarations
- Use declarations
- Function declarations and function parameters
- Type aliases
- struct, union, enum, enum variant declarations, and their named fields
- Constant item declarations
- Static item declarations
- Trait item declarations and their associated items
- External block items
macro_rulesdeclarations and matcher metavariables
- Implementation associated items
- Generic parameters
- Higher ranked trait bounds
letstatement pattern bindings
macro_useattribute can introduce macro names from another crate
macro_exportattribute can introduce an alias for the macro into the crate root
The following entities are implicitly defined by the language, or are introduced by compiler options and extensions:
- Language prelude:
- Built-in attributes
- Standard library prelude items, attributes, and macros
- Standard library crates in the root module
- External crates linked by the compiler
- Tool attributes
- Lints and tool lint attributes
- Derive helper attributes are valid within an item without being explicitly imported
Additionally, the crate root module does not have a name, but can be referred to with certain path qualifiers or aliases.