Enum rustc_ast::ast::PatKind[][src]

pub enum PatKind {
Show 15 variants Wild, Ident(BindingModeIdentOption<P<Pat>>), Struct(Option<QSelf>, PathVec<PatField>, bool), TupleStruct(Option<QSelf>, PathVec<P<Pat>>), Or(Vec<P<Pat>>), Path(Option<QSelf>, Path), Tuple(Vec<P<Pat>>), Box(P<Pat>), Ref(P<Pat>, Mutability), Lit(P<Expr>), Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>), Slice(Vec<P<Pat>>), Rest, Paren(P<Pat>), MacCall(MacCall),
Expand description

All the different flavors of pattern that Rust recognizes.



Represents a wildcard pattern (_).


A PatKind::Ident may either be a new bound variable (ref mut binding @ OPT_SUBPATTERN), or a unit struct/variant pattern, or a const pattern (in the last two cases the third field must be None). Disambiguation cannot be done with parser alone, so it happens during name resolution.

Tuple Fields of Ident

0: BindingMode1: Ident2: Option<P<Pat>>
Struct(Option<QSelf>, PathVec<PatField>, bool)

A struct or struct variant pattern (e.g., Variant {x, y, ..}). The bool is true in the presence of a ...

Tuple Fields of Struct

0: Option<QSelf>1: Path2: Vec<PatField>3: bool
TupleStruct(Option<QSelf>, PathVec<P<Pat>>)

A tuple struct/variant pattern (Variant(x, y, .., z)).

Tuple Fields of TupleStruct

0: Option<QSelf>1: Path2: Vec<P<Pat>>

An or-pattern A | B | C. Invariant: pats.len() >= 2.

Tuple Fields of Or

0: Vec<P<Pat>>
Path(Option<QSelf>, Path)

A possibly qualified path pattern. Unqualified path patterns A::B::C can legally refer to variants, structs, constants or associated constants. Qualified path patterns <A>::B::C/<A as Trait>::B::C can only legally refer to associated constants.

Tuple Fields of Path

0: Option<QSelf>1: Path

A tuple pattern ((a, b)).

Tuple Fields of Tuple

0: Vec<P<Pat>>

A box pattern.

Tuple Fields of Box

0: P<Pat>
Ref(P<Pat>, Mutability)

A reference pattern (e.g., &mut (a, b)).

Tuple Fields of Ref

0: P<Pat>1: Mutability

A literal.

Tuple Fields of Lit

0: P<Expr>
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>)

A range pattern (e.g., 1...2, 1..2, 1.., ..2, 1..=2, ..=2).

Tuple Fields of Range

0: Option<P<Expr>>1: Option<P<Expr>>2: Spanned<RangeEnd>

A slice pattern [a, b, c].

Tuple Fields of Slice

0: Vec<P<Pat>>

A rest pattern ...

Syntactically it is valid anywhere.

Semantically however, it only has meaning immediately inside:

In all of these cases, an additional restriction applies, only one rest pattern may occur in the pattern sequences.


Parentheses in patterns used for grouping (i.e., (PAT)).

Tuple Fields of Paren

0: P<Pat>

A macro pattern; pre-expansion.

Tuple Fields of MacCall

0: MacCall

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.


Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 96 bytes

Size for each variant: