Operator expressions OperatorExpression -> BorrowExpression | DereferenceExpression | TryPropagationExpression | NegationExpression | ArithmeticOrLogicalExpression | ComparisonExpression | LazyBooleanExpression | TypeCastExpression | Assign...
Block expressions BlockExpression -> `{` InnerAttribute* Statements? `}` BlockExpressionNoInnerAttributes -> `{` Statements? `}` Statements -> Statement+ | Statement+ ExpressionWithoutBlock | ExpressionWithoutBlock A block expression, or bl...
Path expressions PathExpression -> PathInExpression | QualifiedPathInExpression A path used as an expression context denotes either a local variable or an item. Path expressions that resolve to local or static variables are place expression...
Literal expressions LiteralExpression -> CHAR_LITERAL | STRING_LITERAL | RAW_STRING_LITERAL | BYTE_LITERAL | BYTE_STRING_LITERAL | RAW_BYTE_STRING_LITERAL | C_STRING_LITERAL | RAW_C_STRING_LITERAL | INTEGER_LITERAL | FLOAT_LITERAL | `true`...
Expressions Expression -> ExpressionWithoutBlock | ExpressionWithBlock ExpressionWithoutBlock -> OuterAttribute* ExpressionWithoutBlockNoAttrs ExpressionWithoutBlockNoAttrs -> LiteralExpression | PathExpression | OperatorExpression | Groupe...
Statements Statement -> `;` | Item | LetStatement | ExpressionStatement | OuterAttribute* MacroInvocationSemi A statement is a component of a block, which is in turn a component of an outer expression or function. Rust has two kinds of stat...
Statements and expressions Rust is primarily an expression language. This means that most forms of value-producing or effect-causing evaluation are directed by the uniform syntax category of expressions. Each kind of expression can typicall...
Debugger attributes The following attributes are used for enhancing the debugging experience when using third-party debuggers like GDB or WinDbg. The debugger_visualizer attribute The debugger_visualizer attribute can be used to embed a deb...
Type system attributes The following attributes are used for changing how a type can be used. The non_exhaustive attribute The non_exhaustive attribute indicates that a type or variant may have more fields or variants added in the future. I...
Limits The following attributes affect compile-time limits. The recursion_limit attribute The recursion_limit attribute may be applied at the crate level to set the maximum depth for potentially infinitely-recursive compile-time operations...
Code generation attributes The following attributes are used for controlling code generation. The inline attribute The inline attribute suggests whether a copy of the attributed function's code should be placed in the caller rather than gen...
Diagnostic attributes The following attributes are used for controlling or generating diagnostic messages during compilation. Lint check attributes A lint check names a potentially undesirable coding pattern, such as unreachable code or omi...
Derive The derive [attribute][attributes] invokes one or more derive macros, allowing new items to be automatically generated for data structures. You can create derive macros with procedural macros. [!EXAMPLE] The [PartialEq][macro@Partial...
Testing attributes The following attributes are used for specifying functions for performing tests. Compiling a crate in "test" mode enables building the test functions along with a test harness for executing the tests. Enabling the test mo...
Attributes InnerAttribute -> `#` `!` `[` Attr `]` OuterAttribute -> `#` `[` Attr `]` Attr -> SimplePath AttrInput? | `unsafe` `(` SimplePath AttrInput? `)` AttrInput -> DelimTokenTree | `=` Expression An attribute is a general, free-form me...
Associated items AssociatedItem -> OuterAttribute* ( MacroInvocationSemi | ( Visibility? ( TypeAlias | ConstantItem | Function ) ) ) Associated Items are the items declared in traits or defined in implementations. They are called this becau...
Generic parameters GenericParams -> `<` ( GenericParam (`,` GenericParam)* `,`? )? `>` GenericParam -> OuterAttribute* ( LifetimeParam | TypeParam | ConstParam ) LifetimeParam -> Lifetime ( `:` LifetimeBounds )? TypeParam -> IDENTIFIER ( `:...
External blocks ExternBlock -> `unsafe`?[^unsafe-2024] `extern` Abi? `{` InnerAttribute* ExternalItem* `}` ExternalItem -> OuterAttribute* ( MacroInvocationSemi | Visibility? StaticItem | Visibility? Function ) [^unsafe-2024]: Starting with...
Implementations Implementation -> InherentImpl | TraitImpl InherentImpl -> `impl` GenericParams? Type WhereClause? `{` InnerAttribute* AssociatedItem* `}` TraitImpl -> `unsafe`? `impl` GenericParams? `!`? TypePath `for` Type WhereClause? `{...
Traits Trait -> `unsafe`? `trait` IDENTIFIER GenericParams? ( `:` Bounds? )? WhereClause? `{` InnerAttribute* AssociatedItem* `}` A trait describes an abstract interface that types can implement. This interface consists of associated items,...