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. For details on the syntax of this grammar, see notation.grammar.syntax.

Items summary

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

Item
    OuterAttribute* ( VisItem | MacroItem )

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

MacroItem
      MacroInvocationSemi
    | MacroRulesDefinition

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

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

ImplementationInherentImpl | TraitImpl

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

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

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

Enumeration
    enum IDENTIFIER GenericParams? WhereClause? { EnumVariants? }

EnumVariantsEnumVariant ( , EnumVariant )* ,?

EnumVariant
    OuterAttribute* Visibility?
    IDENTIFIER ( EnumVariantTuple | EnumVariantStruct )? EnumVariantDiscriminant?

EnumVariantTuple( TupleFields? )

EnumVariantStruct{ StructFields? }

EnumVariantDiscriminant= Expression

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

Union
    union IDENTIFIER GenericParams? WhereClause? { StructFields? }

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

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

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

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

GenericParamOuterAttribute* ( LifetimeParam | TypeParam | ConstParam )

LifetimeParamLifetime ( : LifetimeBounds? )?

TypeParamIDENTIFIER ( : Bounds? )? ( = Type )?

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

WhereClausewhere ( WhereClauseItem , )* WhereClauseItem?

WhereClauseItem
      LifetimeWhereClauseItem
    | TypeBoundWhereClauseItem

LifetimeWhereClauseItemLifetime : LifetimeBounds?

TypeBoundWhereClauseItemForLifetimes? Type : Bounds?

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

TypeAlias
    type IDENTIFIER GenericParams? ( : Bounds? )?
        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

ExternCrateextern crate CrateRef AsClause? ;

CrateRefIDENTIFIER | self

AsClauseas ( IDENTIFIER | _ )

Crate
    InnerAttribute*
    Item*

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

Attributes summary

Syntax
ProcMacroDeriveAttribute
    proc_macro_derive ( DeriveMacroName ( , DeriveMacroAttributes )? ,? )

DeriveMacroNameIDENTIFIER

DeriveMacroAttributes
    attributes ( ( IDENTIFIER ( , IDENTIFIER )* ,? )? )

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 )* ,? )? )

CollapseDebuginfoAttributecollapse_debuginfo ( CollapseDebuginfoOption )

CollapseDebuginfoOption
      yes
    | no
    | external

InlineAttribute
      inline ( always )
    | inline ( never )
    | inline

Lexer summary

Lexer
IDENTIFIER_OR_KEYWORD → ( XID_Start | _ ) XID_Continue*

XID_Start<XID_Start defined by Unicode>

XID_Continue<XID_Continue defined by Unicode>

RAW_IDENTIFIERr# IDENTIFIER_OR_KEYWORD

NON_KEYWORD_IDENTIFIERIDENTIFIER_OR_KEYWORDexcept a strict or reserved keyword

IDENTIFIERNON_KEYWORD_IDENTIFIER | RAW_IDENTIFIER

RESERVED_RAW_IDENTIFIER
    r# ( _ | crate | self | Self | super ) !XID_Continue

STRICT_KEYWORDS
      _
    | as
    | async
    | await
    | break
    | const
    | continue
    | crate
    | dyn
    | else
    | enum
    | extern
    | false
    | fn
    | for
    | if
    | impl
    | in
    | let
    | loop
    | match
    | mod
    | move
    | mut
    | pub
    | ref
    | return
    | self
    | Self
    | static
    | struct
    | super
    | trait
    | true
    | type
    | unsafe
    | use
    | where
    | while

RESERVED_KEYWORDS
      abstract
    | become
    | box
    | do
    | final
    | gen
    | macro
    | override
    | priv
    | try
    | typeof
    | unsized
    | virtual
    | yield

WEAK_KEYWORDS
      'static
    | macro_rules
    | raw
    | safe
    | union

COMMENT
      LINE_COMMENT
    | INNER_LINE_DOC
    | OUTER_LINE_DOC
    | INNER_BLOCK_DOC
    | OUTER_BLOCK_DOC
    | BLOCK_COMMENT

LINE_COMMENT
      // ( ~[/ ! LF] | // ) ~LF*
    | // EOF
    | //immediately followed by LF

BLOCK_COMMENT
    /* !( ! | * ![* /] ) ^
      ( BLOCK_COMMENT_OR_DOC | ( !*/ CHAR ) )*
    */

INNER_LINE_DOC
    //! ^ LINE_DOC_COMMENT_CONTENT ( LF | EOF )

LINE_DOC_COMMENT_CONTENT → ( !CR ~LF )*

INNER_BLOCK_DOC
    /*! ^ ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* */

OUTER_LINE_DOC
    /// ^ LINE_DOC_COMMENT_CONTENT ( LF | EOF )

OUTER_BLOCK_DOC
    /** ![* /]
      ^
      ( ~[* CR] | BLOCK_COMMENT_OR_DOC )
      ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )*
    */

BLOCK_CHAR → ( !( */ | CR ) CHAR )

BLOCK_COMMENT_OR_DOC
      INNER_BLOCK_DOC
    | OUTER_BLOCK_DOC
    | BLOCK_COMMENT

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

SUFFIX
      _ ^ XID_Continue+
    | XID_Start XID_Continue*

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..=6valid hex char value }

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

STRING_CONTINUE\ LF [TAB LF CR SP]*

RAW_STRING_LITERAL
      r " ^ RAW_STRING_CONTENT " SUFFIX?
    | r #n:1..=255 ^ " RAW_STRING_CONTENT_HASHED " #n SUFFIX?

RAW_STRING_CONTENT → ( !" ~CR )*

RAW_STRING_CONTENT_HASHED → ( !( " #n ) ~CR )*

BYTE_LITERAL
    b' ^ ( ASCII_FOR_CHAR | BYTE_ESCAPE ) ' SUFFIX?

ASCII_FOR_CHAR → ![' \ LF CR TAB] ASCII

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 → ![" \ CR] ASCII

RAW_BYTE_STRING_LITERAL
      br " ^ RAW_BYTE_STRING_CONTENT " SUFFIX?
    | br #n:1..=255 ^ " RAW_BYTE_STRING_CONTENT_HASHED " #n SUFFIX?

RAW_BYTE_STRING_CONTENT → ( !" ASCII_FOR_RAW )*

RAW_BYTE_STRING_CONTENT_HASHED → ( !( " #n ) ASCII_FOR_RAW )*

ASCII_FOR_RAW → !CR ASCII

C_STRING_LITERAL
    c" ^ (
        ~[" \ CR NUL]
      | !( \0 | \x00 ) BYTE_ESCAPE
      | !( \u{ ( 0 _* )1..=6 } ) UNICODE_ESCAPE
      | STRING_CONTINUE
    )* " SUFFIX?

RAW_C_STRING_LITERAL
      cr " ^ RAW_C_STRING_CONTENT " SUFFIX?
    | cr #n:1..=255 ^ " RAW_C_STRING_CONTENT_HASHED " #n SUFFIX?

RAW_C_STRING_CONTENT → ( !" ~[CR NUL] )*

RAW_C_STRING_CONTENT_HASHED → ( !( " #n ) ~[CR NUL] )*

INTEGER_LITERAL
    ( BIN_LITERAL | OCT_LITERAL | HEX_LITERAL | DEC_LITERAL )
    ^ !RESERVED_FLOAT SUFFIX?

DEC_LITERALDEC_DIGIT ( DEC_DIGIT | _ )*

BIN_LITERAL0b ^ _* BIN_DIGIT ( BIN_DIGIT | _ )* ![e E 2-9]

OCT_LITERAL0o ^ _* OCT_DIGIT ( OCT_DIGIT | _ )* ![e E 8-9]

HEX_LITERAL0x ^ _* HEX_DIGIT ( HEX_DIGIT | _ )*

BIN_DIGIT → [0-1]

OCT_DIGIT → [0-7]

DEC_DIGIT → [0-9]

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

RESERVED_FLOAT. !( . | _ | XID_Start )

TUPLE_INDEXDEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL

FLOAT_LITERAL
      DEC_LITERAL ( . DEC_LITERAL )? FLOAT_EXPONENT SUFFIX?
    | DEC_LITERAL . DEC_LITERAL SUFFIX?
    | DEC_LITERAL . !( . | _ | XID_Start )

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

LIFETIME_TOKEN
      RAW_LIFETIME
    | ' IDENTIFIER_OR_KEYWORD !'

LIFETIME_OR_LABEL
      RAW_LIFETIME
    | ' NON_KEYWORD_IDENTIFIER !'

RAW_LIFETIME
    'r# ^ IDENTIFIER_OR_KEYWORD !'

RESERVED_RAW_LIFETIME'r# ( _ | crate | self | Self | super ) !( ' | XID_Continue )

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

RESERVED_TOKEN
      RESERVED_GUARDED_STRING_LITERAL
    | 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..

SHEBANG
    #! !( ( WHITESPACE | LINE_COMMENT | SHEBANG_BLOCK_COMMENT )* [ )
    ~LF* ( LF | EOF )

SHEBANG_BLOCK_COMMENT
    /* !( ! | * ![* /] )
      ( SHEBANG_NESTED_BLOCK_COMMENT | ( !( */ | /* ) CHAR ) )*
    */

SHEBANG_NESTED_BLOCK_COMMENT
    /*
      ( SHEBANG_NESTED_BLOCK_COMMENT | ( !( */ | /* ) CHAR ) )*
    */

CHAR → [U+0000-U+D7FF U+E000-U+10FFFF] // a Unicode scalar value

ASCII → [U+0000-U+007F]

NUL → U+0000

EOF → !CHAR // End of file or input

WHITESPACE
      U+0009 // Horizontal tab, '\t'
    | U+000A // Line feed, '\n'
    | U+000B // Vertical tab
    | U+000C // Form feed
    | U+000D // Carriage return, '\r'
    | U+0020 // Space, ' '
    | U+0085 // Next line
    | U+200E // Left-to-right mark
    | U+200F // Right-to-left mark
    | U+2028 // Line separator
    | U+2029 // Paragraph separator

TAB → U+0009 // Horizontal tab, '\t'

LF → U+000A // Line feed, '\n'

CR → U+000D // Carriage return, '\r'

SP → U+0020 // Space, ' '

XID_Start `XID_Start` defined by Unicode
XID_Continue `XID_Continue` defined by Unicode
NON_KEYWORD_IDENTIFIER except a strict or reserved keyword IDENTIFIER_OR_KEYWORD
RESERVED_RAW_IDENTIFIER r# _ crate self Self super not followed by XID_Continue
STRICT_KEYWORDS _ as async await break const continue crate dyn else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while
RESERVED_KEYWORDS abstract become box do final gen macro override priv try typeof unsized virtual yield
WEAK_KEYWORDS 'static macro_rules raw safe union
LINE_COMMENT // ⚠️ with the exception of / ! LF CHAR // ⚠️ with the exception of LF CHAR // EOF immediately followed by LF //
BLOCK_COMMENT /* not followed by ! * not followed by * / no backtracking BLOCK_COMMENT_OR_DOC not followed by */ CHAR */
LINE_DOC_COMMENT_CONTENT not followed by CR ⚠️ with the exception of LF CHAR
OUTER_BLOCK_DOC /** not followed by * / no backtracking ⚠️ with the exception of * CR CHAR BLOCK_COMMENT_OR_DOC BLOCK_COMMENT_OR_DOC BLOCK_CHAR */
BLOCK_CHAR not followed by */ CR CHAR
UNICODE_ESCAPE \u{ valid hex char value at most 5 more times HEX_DIGIT _ }
RAW_STRING_LITERAL r " no backtracking RAW_STRING_CONTENT " SUFFIX r repeat count n at most 254 more times # no backtracking " RAW_STRING_CONTENT_HASHED " repeat exactly n times # SUFFIX
RAW_STRING_CONTENT not followed by " ⚠️ with the exception of CR CHAR
RAW_STRING_CONTENT_HASHED not followed by " repeat exactly n times # ⚠️ with the exception of CR CHAR
RAW_BYTE_STRING_LITERAL br " no backtracking RAW_BYTE_STRING_CONTENT " SUFFIX br repeat count n at most 254 more times # no backtracking " RAW_BYTE_STRING_CONTENT_HASHED " repeat exactly n times # SUFFIX
RAW_BYTE_STRING_CONTENT_HASHED not followed by " repeat exactly n times # ASCII_FOR_RAW
C_STRING_LITERAL c" no backtracking ⚠️ with the exception of " \ CR NUL CHAR not followed by \0 \x00 BYTE_ESCAPE not followed by \u{ at most 5 more times 0 _ } UNICODE_ESCAPE STRING_CONTINUE " SUFFIX
RAW_C_STRING_LITERAL cr " no backtracking RAW_C_STRING_CONTENT " SUFFIX cr repeat count n at most 254 more times # no backtracking " RAW_C_STRING_CONTENT_HASHED " repeat exactly n times # SUFFIX
RAW_C_STRING_CONTENT not followed by " ⚠️ with the exception of CR NUL CHAR
RAW_C_STRING_CONTENT_HASHED not followed by " repeat exactly n times # ⚠️ with the exception of CR NUL CHAR
BIN_LITERAL 0b no backtracking _ BIN_DIGIT BIN_DIGIT _ not followed by e E 2-9
OCT_LITERAL 0o no backtracking _ OCT_DIGIT OCT_DIGIT _ not followed by e E 8-9
HEX_DIGIT 0-9 a-f A-F
RESERVED_FLOAT . not followed by . _ XID_Start
FLOAT_EXPONENT e E no backtracking + - _ DEC_DIGIT DEC_DIGIT _
RAW_LIFETIME 'r# no backtracking IDENTIFIER_OR_KEYWORD not followed by '
RESERVED_RAW_LIFETIME 'r# _ crate self Self super not followed by ' XID_Continue
PUNCTUATION ... ..= <<= >>= != %= && &= *= += -= -> .. /= :: <- << <= == => >= >> ^= |= || ! # $ % & ( ) * + , - . / : ; < = > ? @ [ ] ^ { | } ~
RESERVED_TOKEN_DOUBLE_QUOTE except `b` or `c` or `r` or `br` or `cr` IDENTIFIER_OR_KEYWORD "
SHEBANG_BLOCK_COMMENT /* not followed by ! * not followed by * / SHEBANG_NESTED_BLOCK_COMMENT not followed by */ /* CHAR */
CHAR U+0000-U+D7FF U+E000-U+10FFFF
ASCII U+0000-U+007F
NUL U+0000
EOF not followed by CHAR
WHITESPACE U+0009 U+000A U+000B U+000C U+000D U+0020 U+0085 U+200E U+200F U+2028 U+2029
TAB U+0009
LF U+000A
CR U+000D
SP U+0020

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

Types summary

Syntax
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* ...

InferredType_

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

ArrayType[ Type ; Expression ]

ImplTraitTypeimpl Bounds?

ImplTraitTypeOneBoundimpl TraitBound?

SliceType[ Type ]

NeverType!

ReferenceType& Lifetime? mut? TypeNoBounds

RawPointerType* ( mut | const ) TypeNoBounds

TraitObjectTypeBounds | dyn Bounds?

TraitObjectTypeOneBoundTraitBound | dyn TraitBound?

Type
      TypeNoBounds
    | ImplTraitType
    | TraitObjectType

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

ParenthesizedType( Type )

Paths summary

Syntax
SimplePath
    ::? SimplePathSegment ( :: SimplePathSegment )*

SimplePathSegment
    IDENTIFIER | super | self | crate | $crate

PathInExpression
    ::? PathExprSegment ( :: PathExprSegment )*

PathExprSegment
    PathIdentSegment ( :: GenericArgs )?

PathIdentSegment
    IDENTIFIER | super | self | Self | crate | $crate

GenericArgs
      < GenericArgList? >
    | ( TypeList? ) ( -> TypeNoBounds )?

GenericArgList
    ( GenericArg , )* GenericArg ,?

TypeList
    ( Type , )* Type ,?

GenericArg
    Lifetime | Type | GenericArgsConst | GenericArgsBinding | GenericArgsBounds

GenericArgsConst
      BlockExpression
    | LiteralExpression
    | - LiteralExpression
    | SimplePathSegment

GenericArgsBinding
    TypePathSegment = Type

GenericArgsBounds
    TypePathSegment : Bounds?

QualifiedPathInExpressionQualifiedPathType ( :: PathExprSegment )+

QualifiedPathType< Type ( as TypePath )? >

QualifiedPathInTypeQualifiedPathType ( :: TypePathSegment )+

TypePath::? TypePathSegment ( :: TypePathSegment )*

TypePathSegmentPathIdentSegment ( ::? GenericArgs )?

Assembly summary

Syntax
AsmArgsAsmAttrFormatString ( , AsmAttrFormatString )* ( , AsmAttrOperand )* ,?

FormatStringSTRING_LITERAL | RAW_STRING_LITERAL | MacroInvocation

AsmAttrFormatString → ( OuterAttribute )* FormatString

AsmOperand
      ClobberAbi
    | AsmOptions
    | RegOperand

AsmAttrOperand → ( OuterAttribute )* AsmOperand

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

Statements summary

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

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

ExpressionStatement
      ExpressionWithoutBlock ;
    | ExpressionWithBlock ;?

Miscellaneous summary

Syntax
BoundsBound ( + Bound )* +?

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

Configuration summary

Expressions summary

Syntax
Expression
      ExpressionWithoutBlock
    | ExpressionWithBlock

ExpressionWithoutBlock
    OuterAttribute* ExpressionWithoutBlockNoAttrs

ExpressionWithoutBlockNoAttrs
      LiteralExpression
    | PathExpression
    | OperatorExpression
    | GroupedExpression
    | ArrayExpression
    | AwaitExpression
    | IndexExpression
    | TupleExpression
    | TupleIndexingExpression
    | StructExpression
    | CallExpression
    | MethodCallExpression
    | FieldExpression
    | ClosureExpression
    | AsyncBlockExpression
    | ContinueExpression
    | BreakExpression
    | RangeExpression
    | ReturnExpression
    | UnderscoreExpression
    | MacroInvocation

ExpressionWithBlock
    OuterAttribute* ExpressionWithBlockNoAttrs

ExpressionWithBlockNoAttrs
      BlockExpression
    | ConstBlockExpression
    | UnsafeBlockExpression
    | LoopExpression
    | IfExpression
    | MatchExpression

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?

MatchExpression
    match Scrutinee {
        InnerAttribute*
        MatchArms?
    }

ScrutineeExpressionexcept StructExpression

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

MatchArmOuterAttribute* Pattern MatchArmGuard?

MatchArmGuardif MatchConditions

MatchConditions
     MatchGuardChain
   | Expression

MatchGuardChainMatchGuardCondition ( && MatchGuardCondition )*

MatchGuardCondition
     Expressionexcept ExcludedMatchConditions
   | OuterAttribute* let Pattern = MatchGuardScrutinee

MatchGuardScrutineeExpressionexcept ExcludedMatchConditions

ExcludedMatchConditions
      LazyBooleanExpression
    | RangeExpr
    | RangeFromExpr
    | RangeInclusiveExpr
    | AssignmentExpression
    | CompoundAssignmentExpression

ArrayExpression[ ArrayElements? ]

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

IndexExpressionExpression [ Expression ]

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

Conditions
      Expressionexcept StructExpression
    | LetChain

LetChainLetChainCondition ( && LetChainCondition )*

LetChainCondition
      Expressionexcept ExcludedConditions
    | OuterAttribute* let Pattern = Scrutineeexcept ExcludedConditions

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

AwaitExpressionExpression . await

FieldExpressionExpression . IDENTIFIER

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

MethodCallExpressionExpression . PathExprSegment ( CallParams? )

PathExpression
      PathInExpression
    | QualifiedPathInExpression

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

RangeExprExpression .. Expression

RangeFromExprExpression ..

RangeToExpr.. Expression

RangeFullExpr..

RangeInclusiveExprExpression ..= Expression

RangeToInclusiveExpr..= Expression

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

ClosureParametersClosureParam ( , ClosureParam )* ,?

ClosureParamOuterAttribute* PatternNoTopAlt ( : Type )?

StructExpression
    PathInExpression { ( StructExprFields | StructBase )? }

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

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

StructBase.. Expression

ReturnExpressionreturn Expression?

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

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

DereferenceExpression* Expression

TryPropagationExpressionExpression ?

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 )

BlockExpression
    {
        InnerAttribute*
        Statements?
    }

BlockExpressionNoInnerAttributes
    {
        Statements?
    }

Statements
      Statement+
    | Statement+ ExpressionWithoutBlock
    | ExpressionWithoutBlock

AsyncBlockExpressionasync move? BlockExpression

ConstBlockExpressionconst BlockExpression

UnsafeBlockExpressionunsafe BlockExpression

CallExpressionExpression ( CallParams? )

CallParamsExpression ( , Expression )* ,?

TupleExpression( TupleElements? )

TupleElements → ( Expression , )+ Expression?

TupleIndexingExpressionExpression . TUPLE_INDEX

UnderscoreExpression_

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

Patterns summary

Syntax
Pattern|? PatternNoTopAlt ( | PatternNoTopAlt )*

PatternNoTopAlt
      PatternWithoutModernRange
    | ModernRangePattern

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

LiteralPattern-? LiteralExpression

IdentifierPatternref? mut? IDENTIFIER ( @ PatternNoTopAlt )?

WildcardPattern_

RestPattern..

ModernRangePattern
      RangeExclusivePattern
    | RangeInclusivePattern
    | RangeFromPattern
    | RangeToExclusivePattern
    | RangeToInclusivePattern

RangeExclusivePattern
      RangePatternBound .. RangePatternBound

RangeInclusivePattern
      RangePatternBound ..= RangePatternBound

RangeFromPattern
      RangePatternBound ..

RangeToExclusivePattern
      .. RangePatternBound

RangeToInclusivePattern
      ..= RangePatternBound

ObsoleteRangePattern
    RangePatternBound ... RangePatternBound

RangePatternBound
      LiteralPattern
    | PathExpression

ReferencePattern → ( & | && ) mut? PatternWithoutModernRange

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