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

Grammar summary

The following is a summary of the grammar production rules.

Lexer summary

Lexer
CHAR<a Unicode scalar value>

NUL → U+0000

TAB → U+0009

LF → U+000A

CR → U+000D

IDENTIFIER_OR_KEYWORD
      XID_Start XID_Continue*
    | _ XID_Continue+

XID_Start<XID_Start defined by Unicode>

XID_Continue<XID_Continue defined by Unicode>

RAW_IDENTIFIERr# IDENTIFIER_OR_KEYWORDexcept crate, self, super, Self

NON_KEYWORD_IDENTIFIERIDENTIFIER_OR_KEYWORDexcept a strict or reserved keyword

IDENTIFIERNON_KEYWORD_IDENTIFIER | RAW_IDENTIFIER

RESERVED_RAW_IDENTIFIERr#_

LINE_COMMENT
      // ( ~[/ ! LF] | // ) ~LF*
    | //

BLOCK_COMMENT
      /*
        ( ~[* !] | ** | BlockCommentOrDoc )
        ( BlockCommentOrDoc | ~*/ )*
      */
    | /**/
    | /***/

INNER_LINE_DOC
    //! ~[LF CR]*

INNER_BLOCK_DOC
    /*! ( BlockCommentOrDoc | ~[*/ CR] )* */

OUTER_LINE_DOC
    /// ( ~/ ~[LF CR]* )?

OUTER_BLOCK_DOC
    /**
      ( ~* | BlockCommentOrDoc )
      ( BlockCommentOrDoc | ~[*/ CR] )*
    */

BlockCommentOrDoc
      BLOCK_COMMENT
    | OUTER_BLOCK_DOC
    | INNER_BLOCK_DOC

Token
      IDENTIFIER_OR_KEYWORD
    | RAW_IDENTIFIER
    | 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
    | LIFETIME_TOKEN
    | PUNCTUATION
    | RESERVED_TOKEN

SUFFIXIDENTIFIER_OR_KEYWORD

SUFFIX_NO_ESUFFIXnot beginning with e or E

CHAR_LITERAL
    '
        ( ~[' \ LF CR TAB] | QUOTE_ESCAPE | ASCII_ESCAPE | UNICODE_ESCAPE )
    ' SUFFIX?

QUOTE_ESCAPE\' | \"

ASCII_ESCAPE
      \x OCT_DIGIT HEX_DIGIT
    | \n | \r | \t | \\ | \0

UNICODE_ESCAPE
    \u{ ( HEX_DIGIT _* )1..6 }

STRING_LITERAL
    " (
        ~[" \ CR]
      | QUOTE_ESCAPE
      | ASCII_ESCAPE
      | UNICODE_ESCAPE
      | STRING_CONTINUE
    )* " SUFFIX?

STRING_CONTINUE\ LF

RAW_STRING_LITERALr RAW_STRING_CONTENT SUFFIX?

RAW_STRING_CONTENT
      " ( ~CR )* (non-greedy) "
    | # RAW_STRING_CONTENT #

BYTE_LITERAL
    b' ( ASCII_FOR_CHAR | BYTE_ESCAPE ) ' SUFFIX?

ASCII_FOR_CHAR
    <any ASCII (i.e. 0x00 to 0x7F) except ', \, LF, CR, or TAB>

BYTE_ESCAPE
      \x HEX_DIGIT HEX_DIGIT
    | \n | \r | \t | \\ | \0 | \' | \"

BYTE_STRING_LITERAL
    b" ( ASCII_FOR_STRING | BYTE_ESCAPE | STRING_CONTINUE )* " SUFFIX?

ASCII_FOR_STRING
    <any ASCII (i.e 0x00 to 0x7F) except ", \, or CR>

RAW_BYTE_STRING_LITERAL
    br RAW_BYTE_STRING_CONTENT SUFFIX?

RAW_BYTE_STRING_CONTENT
      " ASCII_FOR_RAW* (non-greedy) "
    | # RAW_BYTE_STRING_CONTENT #

ASCII_FOR_RAW
    <any ASCII (i.e. 0x00 to 0x7F) except CR>

C_STRING_LITERAL
    c" (
        ~[" \ CR NUL]
      | BYTE_ESCAPEexcept \0 or \x00
      | UNICODE_ESCAPEexcept \u{0}, \u{00}, …, \u{000000}
      | STRING_CONTINUE
    )* " SUFFIX?

RAW_C_STRING_LITERAL
    cr RAW_C_STRING_CONTENT SUFFIX?

RAW_C_STRING_CONTENT
      " ( ~[CR NUL] )* (non-greedy) "
    | # RAW_C_STRING_CONTENT #

INTEGER_LITERAL
    ( DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) SUFFIX_NO_E?

DEC_LITERALDEC_DIGIT ( DEC_DIGIT | _ )*

BIN_LITERAL0b ( BIN_DIGIT | _ )* BIN_DIGIT ( BIN_DIGIT | _ )*

OCT_LITERAL0o ( OCT_DIGIT | _ )* OCT_DIGIT ( OCT_DIGIT | _ )*

HEX_LITERAL0x ( HEX_DIGIT | _ )* HEX_DIGIT ( HEX_DIGIT | _ )*

BIN_DIGIT → [0-1]

OCT_DIGIT → [0-7]

DEC_DIGIT → [0-9]

HEX_DIGIT → [0-9 a-f A-F]

TUPLE_INDEXINTEGER_LITERAL

FLOAT_LITERAL
      DEC_LITERAL .not immediately followed by ., _ or an XID_Start character
    | DEC_LITERAL . DEC_LITERAL SUFFIX_NO_E?
    | DEC_LITERAL ( . DEC_LITERAL )? FLOAT_EXPONENT SUFFIX?

FLOAT_EXPONENT
    ( e | E ) ( + | - )? ( DEC_DIGIT | _ )* DEC_DIGIT ( DEC_DIGIT | _ )*

RESERVED_NUMBER
      BIN_LITERAL [2-9]
    | OCT_LITERAL [8-9]
    | ( BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) .not immediately followed by ., _ or an XID_Start character
    | ( BIN_LITERAL | OCT_LITERAL ) ( e | E )
    | 0b _* <end of input or not BIN_DIGIT>
    | 0o _* <end of input or not OCT_DIGIT>
    | 0x _* <end of input or not HEX_DIGIT>
    | DEC_LITERAL ( . DEC_LITERAL )? ( e | E ) ( + | - )? <end of input or not DEC_DIGIT>

LIFETIME_TOKEN
      ' IDENTIFIER_OR_KEYWORDnot immediately followed by '
    | '_not immediately followed by '
    | RAW_LIFETIME

LIFETIME_OR_LABEL
      ' NON_KEYWORD_IDENTIFIERnot immediately followed by '
    | RAW_LIFETIME

RAW_LIFETIME
    'r# IDENTIFIER_OR_KEYWORDexcept crate, self, super, Self and not immediately followed by '

RESERVED_RAW_LIFETIME'r#_not immediately followed by '

PUNCTUATION
      =
    | <
    | <=
    | ==
    | !=
    | >=
    | >
    | &&
    | ||
    | !
    | ~
    | +
    | -
    | *
    | /
    | %
    | ^
    | &
    | |
    | <<
    | >>
    | +=
    | -=
    | *=
    | /=
    | %=
    | ^=
    | &=
    | |=
    | <<=
    | >>=
    | @
    | .
    | ..
    |
    | ..=
    | ,
    | ;
    | :
    | ::
    | ->
    | <-
    | =>
    | #
    | $
    | ?
    | _
    | {
    | }
    | [
    | ]
    | (
    | )

RESERVED_TOKEN
      RESERVED_GUARDED_STRING_LITERAL
    | RESERVED_NUMBER
    | RESERVED_POUNDS
    | RESERVED_RAW_IDENTIFIER
    | RESERVED_RAW_LIFETIME
    | RESERVED_TOKEN_DOUBLE_QUOTE
    | RESERVED_TOKEN_LIFETIME
    | RESERVED_TOKEN_POUND
    | RESERVED_TOKEN_SINGLE_QUOTE

RESERVED_TOKEN_DOUBLE_QUOTE
    ( IDENTIFIER_OR_KEYWORDexcept b or c or r or br or cr | _ ) "

RESERVED_TOKEN_SINGLE_QUOTE
    ( IDENTIFIER_OR_KEYWORDexcept b | _ ) '

RESERVED_TOKEN_POUND
    ( IDENTIFIER_OR_KEYWORDexcept r or br or cr | _ ) #

RESERVED_TOKEN_LIFETIME
    ' ( IDENTIFIER_OR_KEYWORDexcept r | _ ) #

RESERVED_GUARDED_STRING_LITERAL#+ STRING_LITERAL

RESERVED_POUNDS#2..

CHAR a Unicode scalar value
NUL U+0000
TAB U+0009
LF U+000A
CR U+000D
XID_Start `XID_Start` defined by Unicode
XID_Continue `XID_Continue` defined by Unicode
RAW_IDENTIFIER r# except `crate`, `self`, `super`, `Self` IDENTIFIER_OR_KEYWORD
NON_KEYWORD_IDENTIFIER except a strict or reserved keyword IDENTIFIER_OR_KEYWORD
LINE_COMMENT // ⚠️ with the exception of / ! LF CHAR // ⚠️ with the exception of LF CHAR //
BLOCK_COMMENT /* ⚠️ with the exception of * ! CHAR ** BlockCommentOrDoc BlockCommentOrDoc ⚠️ with the exception of */ CHAR */ /**/ /***/
INNER_LINE_DOC //! ⚠️ with the exception of LF CR CHAR
INNER_BLOCK_DOC /*! BlockCommentOrDoc ⚠️ with the exception of */ CR CHAR */
OUTER_LINE_DOC /// ⚠️ with the exception of / CHAR ⚠️ with the exception of LF CR CHAR
OUTER_BLOCK_DOC /** ⚠️ with the exception of * CHAR BlockCommentOrDoc BlockCommentOrDoc ⚠️ with the exception of */ CR CHAR */
SUFFIX_NO_E not beginning with `e` or `E` SUFFIX
UNICODE_ESCAPE \u{ at most 5 more times HEX_DIGIT _ }
RAW_STRING_CONTENT " non-greedy ⚠️ with the exception of CR CHAR " # RAW_STRING_CONTENT #
ASCII_FOR_CHAR any ASCII (i.e. 0x00 to 0x7F) except `'`, `\`, LF, CR, or TAB
ASCII_FOR_STRING any ASCII (i.e 0x00 to 0x7F) except `"`, `\`, or CR
ASCII_FOR_RAW any ASCII (i.e. 0x00 to 0x7F) except CR
C_STRING_LITERAL c" ⚠️ with the exception of " \ CR NUL CHAR except `\0` or `\x00` BYTE_ESCAPE except `\u{0}`, `\u{00}`, …, `\u{000000}` UNICODE_ESCAPE STRING_CONTINUE " SUFFIX
RAW_C_STRING_CONTENT " non-greedy ⚠️ with the exception of CR NUL CHAR " # RAW_C_STRING_CONTENT #
HEX_DIGIT 0-9 a-f A-F
RESERVED_NUMBER BIN_LITERAL 2-9 OCT_LITERAL 8-9 BIN_LITERAL OCT_LITERAL HEX_LITERAL not immediately followed by `.`, `_` or an XID_Start character . BIN_LITERAL OCT_LITERAL e E 0b _ end of input or not BIN_DIGIT 0o _ end of input or not OCT_DIGIT 0x _ end of input or not HEX_DIGIT DEC_LITERAL . DEC_LITERAL e E + - end of input or not DEC_DIGIT
LIFETIME_TOKEN ' not immediately followed by `'` IDENTIFIER_OR_KEYWORD not immediately followed by `'` '_ RAW_LIFETIME
RAW_LIFETIME 'r# except `crate`, `self`, `super`, `Self` and not immediately followed by `'` IDENTIFIER_OR_KEYWORD
RESERVED_RAW_LIFETIME not immediately followed by `'` 'r#_
PUNCTUATION = < <= == != >= > && || ! ~ + - * / % ^ & | << >> += -= *= /= %= ^= &= |= <<= >>= @ . .. ... ..= , ; : :: -> <- => # $ ? _ { } [ ] ( )
RESERVED_TOKEN_DOUBLE_QUOTE except `b` or `c` or `r` or `br` or `cr` IDENTIFIER_OR_KEYWORD _ "
RESERVED_TOKEN_POUND except `r` or `br` or `cr` IDENTIFIER_OR_KEYWORD _ #

Macros summary

Syntax
MacroInvocation
    SimplePath ! DelimTokenTree

DelimTokenTree
      ( TokenTree* )
    | [ TokenTree* ]
    | { TokenTree* }

TokenTree
    Tokenexcept delimiters | DelimTokenTree

MacroInvocationSemi
      SimplePath ! ( TokenTree* ) ;
    | SimplePath ! [ TokenTree* ] ;
    | SimplePath ! { TokenTree* }

MacroRulesDefinition
    macro_rules ! IDENTIFIER MacroRulesDef

MacroRulesDef
      ( MacroRules ) ;
    | [ MacroRules ] ;
    | { MacroRules }

MacroRules
    MacroRule ( ; MacroRule )* ;?

MacroRule
    MacroMatcher => MacroTranscriber

MacroMatcher
      ( MacroMatch* )
    | [ MacroMatch* ]
    | { MacroMatch* }

MacroMatch
      Tokenexcept $ and delimiters
    | MacroMatcher
    | $ ( IDENTIFIER_OR_KEYWORDexcept crate | RAW_IDENTIFIER | _ ) : MacroFragSpec
    | $ ( MacroMatch+ ) MacroRepSep? MacroRepOp

MacroFragSpec
      block | expr | expr_2021 | ident | item | lifetime | literal
    | meta | pat | pat_param | path | stmt | tt | ty | vis

MacroRepSepTokenexcept delimiters and MacroRepOp

MacroRepOp* | + | ?

MacroTranscriberDelimTokenTree

Items summary

Syntax
Crate
    InnerAttribute*
    Item*

Item
    OuterAttribute* ( VisItem | MacroItem )

VisItem
    Visibility?
    (
        Module
      | ExternCrate
      | UseDeclaration
      | Function
      | TypeAlias
      | Struct
      | Enumeration
      | Union
      | ConstantItem
      | StaticItem
      | Trait
      | Implementation
      | ExternBlock
    )

MacroItem
      MacroInvocationSemi
    | MacroRulesDefinition

Module
      unsafe? mod IDENTIFIER ;
    | unsafe? mod IDENTIFIER {
        InnerAttribute*
        Item*
      }

ExternCrateextern crate CrateRef AsClause? ;

CrateRefIDENTIFIER | self

AsClauseas ( IDENTIFIER | _ )

UseDeclarationuse UseTree ;

UseTree
      ( SimplePath? :: )? *
    | ( SimplePath? :: )? { ( UseTree ( , UseTree )* ,? )? }
    | SimplePath ( as ( IDENTIFIER | _ ) )?

Function
    FunctionQualifiers fn IDENTIFIER GenericParams?
        ( FunctionParameters? )
        FunctionReturnType? WhereClause?
        ( BlockExpression | ; )

FunctionQualifiersconst? async? ItemSafety? ( extern Abi? )?

ItemSafetysafe | unsafe

AbiSTRING_LITERAL | RAW_STRING_LITERAL

FunctionParameters
      SelfParam ,?
    | ( SelfParam , )? FunctionParam ( , FunctionParam )* ,?

SelfParamOuterAttribute* ( ShorthandSelf | TypedSelf )

ShorthandSelf → ( & | & Lifetime )? mut? self

TypedSelfmut? self : Type

FunctionParamOuterAttribute* ( FunctionParamPattern | | Type )

FunctionParamPatternPatternNoTopAlt : ( Type | )

FunctionReturnType-> Type

TypeAlias
    type IDENTIFIER GenericParams? ( : TypeParamBounds )?
        WhereClause?
        ( = Type WhereClause? )? ;

Struct
      StructStruct
    | TupleStruct

StructStruct
    struct IDENTIFIER GenericParams? WhereClause? ( { StructFields? } | ; )

TupleStruct
    struct IDENTIFIER GenericParams? ( TupleFields? ) WhereClause? ;

StructFieldsStructField ( , StructField )* ,?

StructFieldOuterAttribute* Visibility? IDENTIFIER : Type

TupleFieldsTupleField ( , TupleField )* ,?

TupleFieldOuterAttribute* Visibility? Type

Enumeration
    enum IDENTIFIER GenericParams? WhereClause? { EnumItems? }

EnumItemsEnumItem ( , EnumItem )* ,?

EnumItem
    OuterAttribute* Visibility?
    IDENTIFIER ( EnumItemTuple | EnumItemStruct )? EnumItemDiscriminant?

EnumItemTuple( TupleFields? )

EnumItemStruct{ StructFields? }

EnumItemDiscriminant= Expression

Union
    union IDENTIFIER GenericParams? WhereClause? { StructFields? }

ConstantItem
    const ( IDENTIFIER | _ ) : Type ( = Expression )? ;

StaticItem
    ItemSafety? static mut? IDENTIFIER : Type ( = Expression )? ;

Trait
    unsafe? trait IDENTIFIER GenericParams? ( : TypeParamBounds? )? WhereClause?
    {
        InnerAttribute*
        AssociatedItem*
    }

ImplementationInherentImpl | TraitImpl

InherentImpl
    impl GenericParams? Type WhereClause? {
        InnerAttribute*
        AssociatedItem*
    }

TraitImpl
    unsafe? impl GenericParams? !? TypePath for Type
    WhereClause?
    {
        InnerAttribute*
        AssociatedItem*
    }

ExternBlock
    unsafe? extern Abi? {
        InnerAttribute*
        ExternalItem*
    }

ExternalItem
    OuterAttribute* (
        MacroInvocationSemi
      | Visibility? StaticItem
      | Visibility? Function
    )

GenericParams< ( GenericParam ( , GenericParam )* ,? )? >

GenericParamOuterAttribute* ( LifetimeParam | TypeParam | ConstParam )

LifetimeParamLifetime ( : LifetimeBounds )?

TypeParamIDENTIFIER ( : TypeParamBounds? )? ( = Type )?

ConstParam
    const IDENTIFIER : Type
    ( = BlockExpression | IDENTIFIER | -? LiteralExpression )?

WhereClausewhere ( WhereClauseItem , )* WhereClauseItem?

WhereClauseItem
      LifetimeWhereClauseItem
    | TypeBoundWhereClauseItem

LifetimeWhereClauseItemLifetime : LifetimeBounds

TypeBoundWhereClauseItemForLifetimes? Type : TypeParamBounds?

AssociatedItem
    OuterAttribute* (
        MacroInvocationSemi
      | ( Visibility? ( TypeAlias | ConstantItem | Function ) )
    )

Visibility
      pub
    | pub ( crate )
    | pub ( self )
    | pub ( super )
    | pub ( in SimplePath )

ItemSafety safe unsafe
Visibility pub pub ( crate ) pub ( self ) pub ( super ) pub ( in SimplePath )

Configuration summary

Attributes summary

Syntax
InnerAttribute# ! [ Attr ]

OuterAttribute# [ Attr ]

Attr
      SimplePath AttrInput?
    | unsafe ( SimplePath AttrInput? )

AttrInput
      DelimTokenTree
    | = Expression

MetaItem
      SimplePath
    | SimplePath = Expression
    | SimplePath ( MetaSeq? )

MetaSeq
    MetaItemInner ( , MetaItemInner )* ,?

MetaItemInner
      MetaItem
    | Expression

MetaWord
    IDENTIFIER

MetaNameValueStr
    IDENTIFIER = ( STRING_LITERAL | RAW_STRING_LITERAL )

MetaListPaths
    IDENTIFIER ( ( SimplePath ( , SimplePath )* ,? )? )

MetaListIdents
    IDENTIFIER ( ( IDENTIFIER ( , IDENTIFIER )* ,? )? )

MetaListNameValueStr
    IDENTIFIER ( ( MetaNameValueStr ( , MetaNameValueStr )* ,? )? )

Statements summary

Syntax
Statement
      ;
    | Item
    | LetStatement
    | ExpressionStatement
    | OuterAttribute* MacroInvocationSemi

LetStatement
    OuterAttribute* let PatternNoTopAlt ( : Type )?
    (
          = Expression
        | = Expressionexcept LazyBooleanExpression or end with a } else BlockExpression
    )? ;

ExpressionStatement
      ExpressionWithoutBlock ;
    | ExpressionWithBlock ;?

Expressions summary

Syntax
Expression
      ExpressionWithoutBlock
    | ExpressionWithBlock

ExpressionWithoutBlock
    OuterAttribute*
    (
        LiteralExpression
      | PathExpression
      | OperatorExpression
      | GroupedExpression
      | ArrayExpression
      | AwaitExpression
      | IndexExpression
      | TupleExpression
      | TupleIndexingExpression
      | StructExpression
      | CallExpression
      | MethodCallExpression
      | FieldExpression
      | ClosureExpression
      | AsyncBlockExpression
      | ContinueExpression
      | BreakExpression
      | RangeExpression
      | ReturnExpression
      | UnderscoreExpression
      | MacroInvocation
    )

ExpressionWithBlock
    OuterAttribute*
    (
        BlockExpression
      | ConstBlockExpression
      | UnsafeBlockExpression
      | LoopExpression
      | IfExpression
      | MatchExpression
    )

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
    | false

PathExpression
      PathInExpression
    | QualifiedPathInExpression

BlockExpression
    {
        InnerAttribute*
        Statements?
    }

Statements
      Statement+
    | Statement+ ExpressionWithoutBlock
    | ExpressionWithoutBlock

AsyncBlockExpressionasync move? BlockExpression

ConstBlockExpressionconst BlockExpression

UnsafeBlockExpressionunsafe BlockExpression

OperatorExpression
      BorrowExpression
    | DereferenceExpression
    | ErrorPropagationExpression
    | NegationExpression
    | ArithmeticOrLogicalExpression
    | ComparisonExpression
    | LazyBooleanExpression
    | TypeCastExpression
    | AssignmentExpression
    | CompoundAssignmentExpression

BorrowExpression
      ( & | && ) Expression
    | ( & | && ) mut Expression
    | ( & | && ) raw const Expression
    | ( & | && ) raw mut Expression

DereferenceExpression* Expression

ErrorPropagationExpressionExpression ?

NegationExpression
      - Expression
    | ! Expression

ArithmeticOrLogicalExpression
      Expression + Expression
    | Expression - Expression
    | Expression * Expression
    | Expression / Expression
    | Expression % Expression
    | Expression & Expression
    | Expression | Expression
    | Expression ^ Expression
    | Expression << Expression
    | Expression >> Expression

ComparisonExpression
      Expression == Expression
    | Expression != Expression
    | Expression > Expression
    | Expression < Expression
    | Expression >= Expression
    | Expression <= Expression

LazyBooleanExpression
      Expression || Expression
    | Expression && Expression

TypeCastExpressionExpression as TypeNoBounds

AssignmentExpressionExpression = Expression

CompoundAssignmentExpression
      Expression += Expression
    | Expression -= Expression
    | Expression *= Expression
    | Expression /= Expression
    | Expression %= Expression
    | Expression &= Expression
    | Expression |= Expression
    | Expression ^= Expression
    | Expression <<= Expression
    | Expression >>= Expression

GroupedExpression( Expression )

ArrayExpression[ ArrayElements? ]

ArrayElements
      Expression ( , Expression )* ,?
    | Expression ; Expression

IndexExpressionExpression [ Expression ]

TupleExpression( TupleElements? )

TupleElements → ( Expression , )+ Expression?

TupleIndexingExpressionExpression . TUPLE_INDEX

StructExpression
    PathInExpression { ( StructExprFields | StructBase )? }

StructExprFields
    StructExprField ( , StructExprField )* ( , StructBase | ,? )

StructExprField
    OuterAttribute*
    (
        IDENTIFIER
      | ( IDENTIFIER | TUPLE_INDEX ) : Expression
    )

StructBase.. Expression

CallExpressionExpression ( CallParams? )

CallParamsExpression ( , Expression )* ,?

MethodCallExpressionExpression . PathExprSegment ( CallParams? )

FieldExpressionExpression . IDENTIFIER

ClosureExpression
    async?
    move?
    ( || | | ClosureParameters? | )
    ( Expression | -> TypeNoBounds BlockExpression )

ClosureParametersClosureParam ( , ClosureParam )* ,?

ClosureParamOuterAttribute* PatternNoTopAlt ( : Type )?

LoopExpression
    LoopLabel? (
        InfiniteLoopExpression
      | PredicateLoopExpression
      | IteratorLoopExpression
      | LabelBlockExpression
    )

InfiniteLoopExpressionloop BlockExpression

PredicateLoopExpressionwhile Conditions BlockExpression

IteratorLoopExpression
    for Pattern in Expressionexcept StructExpression BlockExpression

LoopLabelLIFETIME_OR_LABEL :

BreakExpressionbreak LIFETIME_OR_LABEL? Expression?

LabelBlockExpressionBlockExpression

ContinueExpressioncontinue LIFETIME_OR_LABEL?

RangeExpression
      RangeExpr
    | RangeFromExpr
    | RangeToExpr
    | RangeFullExpr
    | RangeInclusiveExpr
    | RangeToInclusiveExpr

RangeExprExpression .. Expression

RangeFromExprExpression ..

RangeToExpr.. Expression

RangeFullExpr..

RangeInclusiveExprExpression ..= Expression

RangeToInclusiveExpr..= Expression

IfExpression
    if Conditions BlockExpression
    ( else ( BlockExpression | IfExpression ) )?

Conditions
      Expressionexcept StructExpression
    | LetChain

LetChainLetChainCondition ( && LetChainCondition )*

LetChainCondition
      Expressionexcept ExcludedConditions
    | OuterAttribute* let Pattern = Scrutineeexcept ExcludedConditions

ExcludedConditions
      StructExpression
    | LazyBooleanExpression
    | RangeExpr
    | RangeFromExpr
    | RangeInclusiveExpr
    | AssignmentExpression
    | CompoundAssignmentExpression

MatchExpression
    match Scrutinee {
        InnerAttribute*
        MatchArms?
    }

ScrutineeExpressionexcept StructExpression

MatchArms
    ( MatchArm => ( ExpressionWithoutBlock , | ExpressionWithBlock ,? ) )*
    MatchArm => Expression ,?

MatchArmOuterAttribute* Pattern MatchArmGuard?

MatchArmGuardif Expression

ReturnExpressionreturn Expression?

AwaitExpressionExpression . await

UnderscoreExpression_

LetChainCondition except ExcludedConditions Expression OuterAttribute let Pattern = except ExcludedConditions Scrutinee
Scrutinee except StructExpression Expression

Patterns summary

Syntax
Pattern|? PatternNoTopAlt ( | PatternNoTopAlt )*

PatternNoTopAlt
      PatternWithoutRange
    | RangePattern

PatternWithoutRange
      LiteralPattern
    | IdentifierPattern
    | WildcardPattern
    | RestPattern
    | ReferencePattern
    | StructPattern
    | TupleStructPattern
    | TuplePattern
    | GroupedPattern
    | SlicePattern
    | PathPattern
    | MacroInvocation

LiteralPattern-? LiteralExpression

IdentifierPatternref? mut? IDENTIFIER ( @ PatternNoTopAlt )?

WildcardPattern_

RestPattern..

RangePattern
      RangeExclusivePattern
    | RangeInclusivePattern
    | RangeFromPattern
    | RangeToExclusivePattern
    | RangeToInclusivePattern
    | ObsoleteRangePattern

RangeExclusivePattern
      RangePatternBound .. RangePatternBound

RangeInclusivePattern
      RangePatternBound ..= RangePatternBound

RangeFromPattern
      RangePatternBound ..

RangeToExclusivePattern
      .. RangePatternBound

RangeToInclusivePattern
      ..= RangePatternBound

ObsoleteRangePattern
    RangePatternBound RangePatternBound

RangePatternBound
      LiteralPattern
    | PathExpression

ReferencePattern → ( & | && ) mut? PatternWithoutRange

StructPattern
    PathInExpression {
        StructPatternElements?
    }

StructPatternElements
      StructPatternFields ( , | , StructPatternEtCetera )?
    | StructPatternEtCetera

StructPatternFields
    StructPatternField ( , StructPatternField )*

StructPatternField
    OuterAttribute*
    (
        TUPLE_INDEX : Pattern
      | IDENTIFIER : Pattern
      | ref? mut? IDENTIFIER
    )

StructPatternEtCetera..

TupleStructPatternPathInExpression ( TupleStructItems? )

TupleStructItemsPattern ( , Pattern )* ,?

TuplePattern( TuplePatternItems? )

TuplePatternItems
      Pattern ,
    | RestPattern
    | Pattern ( , Pattern )+ ,?

GroupedPattern( Pattern )

SlicePattern[ SlicePatternItems? ]

SlicePatternItemsPattern ( , Pattern )* ,?

PathPatternPathExpression

Types summary

Syntax
Type
      TypeNoBounds
    | ImplTraitType
    | TraitObjectType

TypeNoBounds
      ParenthesizedType
    | ImplTraitTypeOneBound
    | TraitObjectTypeOneBound
    | TypePath
    | TupleType
    | NeverType
    | RawPointerType
    | ReferenceType
    | ArrayType
    | SliceType
    | InferredType
    | QualifiedPathInType
    | BareFunctionType
    | MacroInvocation

ParenthesizedType( Type )

NeverType!

TupleType
      ( )
    | ( ( Type , )+ Type? )

ArrayType[ Type ; Expression ]

SliceType[ Type ]

ReferenceType& Lifetime? mut? TypeNoBounds

RawPointerType* ( mut | const ) TypeNoBounds

BareFunctionType
    ForLifetimes? FunctionTypeQualifiers fn
       ( FunctionParametersMaybeNamedVariadic? ) BareFunctionReturnType?

FunctionTypeQualifiersunsafe? ( extern Abi? )?

BareFunctionReturnType-> TypeNoBounds

FunctionParametersMaybeNamedVariadic
    MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic

MaybeNamedFunctionParameters
    MaybeNamedParam ( , MaybeNamedParam )* ,?

MaybeNamedParam
    OuterAttribute* ( ( IDENTIFIER | _ ) : )? Type

MaybeNamedFunctionParametersVariadic
    ( MaybeNamedParam , )* MaybeNamedParam , OuterAttribute*

TraitObjectTypedyn? TypeParamBounds

TraitObjectTypeOneBounddyn? TraitBound

ImplTraitTypeimpl TypeParamBounds

ImplTraitTypeOneBoundimpl TraitBound

InferredType_

Miscellaneous summary

Syntax
TypeParamBoundsTypeParamBound ( + TypeParamBound )* +?

TypeParamBoundLifetime | TraitBound | UseBound

TraitBound
      ( ? | ForLifetimes )? TypePath
    | ( ( ? | ForLifetimes )? TypePath )

LifetimeBounds → ( Lifetime + )* Lifetime?

Lifetime
      LIFETIME_OR_LABEL
    | 'static
    | '_

UseBounduse UseBoundGenericArgs

UseBoundGenericArgs
      < >
    | < ( UseBoundGenericArg , )* UseBoundGenericArg ,? >

UseBoundGenericArg
      Lifetime
    | IDENTIFIER
    | Self

ForLifetimesfor GenericParams

Paths summary

Assembly summary

Syntax
AsmArgsFormatString ( , FormatString )* ( , AsmOperand )* ,?

FormatStringSTRING_LITERAL | RAW_STRING_LITERAL | MacroInvocation

AsmOperand
      ClobberAbi
    | AsmOptions
    | RegOperand

ClobberAbiclobber_abi ( Abi ( , Abi )* ,? )

AsmOptions
    options ( ( AsmOption ( , AsmOption )* ,? )? )

AsmOption
      pure
    | nomem
    | readonly
    | preserves_flags
    | noreturn
    | nostack
    | att_syntax
    | raw

RegOperand → ( ParamName = )?
    (
          DirSpec ( RegSpec ) Expression
        | DualDirSpec ( RegSpec ) DualDirSpecExpression
        | sym PathExpression
        | const Expression
        | label { Statements? }
    )

ParamNameIDENTIFIER_OR_KEYWORD | RAW_IDENTIFIER

DualDirSpecExpression
      Expression
    | Expression => Expression

RegSpecRegisterClass | ExplicitRegister

RegisterClassIDENTIFIER_OR_KEYWORD

ExplicitRegisterSTRING_LITERAL

DirSpec
      in
    | out
    | lateout

DualDirSpec
      inout
    | inlateout