Generic parameters GenericParams -> `<` ( GenericParam (`,` GenericParam)* `,`? )? `>` GenericParam -> OuterAttribute* ( LifetimeParam | TypeParam | ConstParam ) LifetimeParam -> Lifetime ( `:` LifetimeBounds )? TypeParam -> IDENTIFIER ( `:...
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...
Attributes InnerAttribute -> `#` `!` `[` Attr `]` OuterAttribute -> `#` `[` Attr `]` Attr -> SimplePath AttrInput? | `unsafe` `(` SimplePath AttrInput? `)` AttrInput -> DelimTokenTree | `=` Expression An attribute is a general, free-form me...
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...
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...
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...
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...
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...
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...
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...
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...
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...
Expressions Expression -> ExpressionWithoutBlock | ExpressionWithBlock ExpressionWithoutBlock -> OuterAttribute* ExpressionWithoutBlockNoAttrs ExpressionWithoutBlockNoAttrs -> LiteralExpression | PathExpression | OperatorExpression | Groupe...
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`...
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...
Block expressions BlockExpression -> `{` InnerAttribute* Statements? `}` BlockExpressionNoInnerAttributes -> `{` Statements? `}` Statements -> Statement+ | Statement+ ExpressionWithoutBlock | ExpressionWithoutBlock A block expression, or bl...
Operator expressions OperatorExpression -> BorrowExpression | DereferenceExpression | TryPropagationExpression | NegationExpression | ArithmeticOrLogicalExpression | ComparisonExpression | LazyBooleanExpression | TypeCastExpression | Assign...
Grouped expressions GroupedExpression -> `(` Expression `)` A parenthesized expression wraps a single expression, evaluating to that expression. The syntax for a parenthesized expression is a (, then an expression, called the enclosed opera...
Array and array index expressions Array expressions ArrayExpression -> `[` ArrayElements? `]` ArrayElements -> Expression ( `,` Expression )* `,`? | Expression `;` Expression Array expressions construct arrays. Array expressions come in two...
Tuple and tuple indexing expressions Tuple expressions TupleExpression -> `(` TupleElements? `)` TupleElements -> ( Expression `,` )+ Expression? A tuple expression constructs tuple values. The syntax for tuple expressions is a parenthesize...