PatKind in rustc_ast::ast - Rust (original) (raw)

pub enum PatKind {
Show 20 variants    Missing,
    Wild,
    Ident(BindingMode, Ident, Option<P<Pat>>),
    Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest),
    TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
    Or(ThinVec<P<Pat>>),
    Path(Option<P<QSelf>>, Path),
    Tuple(ThinVec<P<Pat>>),
    Box(P<Pat>),
    Deref(P<Pat>),
    Ref(P<Pat>, Mutability),
    Expr(P<Expr>),
    Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),
    Slice(ThinVec<P<Pat>>),
    Rest,
    Never,
    Guard(P<Pat>, P<Expr>),
    Paren(P<Pat>),
    MacCall(P<MacCall>),
    Err(ErrorGuaranteed),
}

Expand description

All the different flavors of pattern that Rust recognizes.

§

A missing pattern, e.g. for an anonymous param in a bare fn like fn f(u32).

§

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.

§

A struct or struct variant pattern (e.g., Variant {x, y, ..}).

§

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

§

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

§

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.

§

A tuple pattern ((a, b)).

§

A box pattern.

§

A deref pattern (currently deref!() macro-based syntax).

§

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

§

A literal, const block or path.

§

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

§

A slice pattern [a, b, c].

§

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.

§

§

A guard pattern (e.g., x if guard(x)).

§

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

§

A macro pattern; pre-expansion.

§

Placeholder for a pattern that wasn’t syntactically well formed in some way.

§

§

§

§

§

§

§

§

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: 48 bytes

Size for each variant: