Enum rustc_ast::ast::PatKind [−][src]
pub enum PatKind {
Show 15 variants
Wild,
Ident(BindingMode, Ident, Option<P<Pat>>),
Struct(Option<QSelf>, Path, Vec<PatField>, bool),
TupleStruct(Option<QSelf>, Path, Vec<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.
Variants
Represents a wildcard pattern (_
).
Ident(BindingMode, Ident, Option<P<Pat>>)
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
A struct or struct variant pattern (e.g., Variant {x, y, ..}
).
The bool
is true
in the presence of a ..
.
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.
Ref(P<Pat>, Mutability)
A reference pattern (e.g., &mut (a, b)
).
Tuple Fields of Ref
0: P<Pat>
1: Mutability
A literal.
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:
- a slice pattern:
[a, .., b]
, - a binding pattern immediately inside a slice pattern:
[a, r @ ..]
, - a tuple pattern:
(a, .., b)
, - a tuple struct/variant pattern:
$path(a, .., b)
.
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)
).
MacCall(MacCall)
A macro pattern; pre-expansion.
Tuple Fields of MacCall
0: MacCall
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for PatKind
impl !UnwindSafe for PatKind
Blanket Implementations
Mutably borrows from an owned value. Read more
Layout
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:
Wild
: 0 bytesIdent
: 23 bytesStruct
: 95 bytesTupleStruct
: 95 bytesOr
: 31 bytesPath
: 71 bytesTuple
: 31 bytesBox
: 15 bytesRef
: 15 bytesLit
: 15 bytesRange
: 31 bytesSlice
: 31 bytesRest
: 0 bytesParen
: 15 bytesMacCall
: 71 bytes