Enum rustc_mir_build::thir::pattern::deconstruct_pat::Fields [−][src]
pub(super) enum Fields<'p, 'tcx> {
Slice(&'p [Pat<'tcx>]),
Vec(SmallVec<[&'p Pat<'tcx>; 2]>),
Filtered {
fields: SmallVec<[FilteredField<'p, 'tcx>; 2]>,
len: usize,
},
}Expand description
A value can be decomposed into a constructor applied to some fields. This struct represents
those fields, generalized to allow patterns in each field. See also Constructor.
This is constructed from a constructor using Fields::wildcards().
If a private or non_exhaustive field is uninhabited, the code mustn’t observe that it is
uninhabited. For that, we filter these fields out of the matrix. This is handled automatically
in Fields. This filtering is uncommon in practice, because uninhabited fields are rarely used,
so we avoid it when possible to preserve performance.
Variants
Lists of patterns that don’t contain any filtered fields.
Slice and Vec behave the same; the difference is only to avoid allocating and
triple-dereferences when possible. Frankly this is premature optimization, I (Nadrieril)
have not measured if it really made a difference.
Patterns where some of the fields need to be hidden. For all intents and purposes we only
care about the non-hidden fields. We need to keep the real field index for those fields;
we’re morally storing a Vec<(usize, &Pat)> but what we do is more convenient.
len counts the number of non-hidden fields
Fields of Filtered
fields: SmallVec<[FilteredField<'p, 'tcx>; 2]>len: usizeImplementations
Internal use. Use Fields::wildcards() instead.
Must not be used if the pattern is a field of a struct/tuple/variant.
fn wildcards_from_tys(
cx: &MatchCheckCtxt<'p, 'tcx>,
tys: impl IntoIterator<Item = Ty<'tcx>>
) -> Self
fn wildcards_from_tys(
cx: &MatchCheckCtxt<'p, 'tcx>,
tys: impl IntoIterator<Item = Ty<'tcx>>
) -> Self
Convenience; internal use.
Creates a new list of wildcard fields for a given constructor.
Apply a constructor to a list of patterns, yielding a new pattern. self
must have as many elements as this constructor’s arity.
This is roughly the inverse of specialize_constructor.
Examples:
ctor: Constructor::Single
ty: Foo(u32, u32, u32)
self: [10, 20, _]
returns Foo(10, 20, _)
ctor: Constructor::Variant(Option::Some)
ty: Option<bool>
self: [false]
returns Some(false)
Returns the number of patterns. This is the same as the arity of the constructor used to
construct self.
Returns the list of patterns along with the corresponding field indices.
Returns the list of patterns.
fn replace_with_fieldpats(
&self,
new_pats: impl IntoIterator<Item = &'p FieldPat<'tcx>>
) -> Self
fn replace_with_fieldpats(
&self,
new_pats: impl IntoIterator<Item = &'p FieldPat<'tcx>>
) -> Self
Overrides some of the fields with the provided patterns. Exactly like
replace_fields_indexed, except that it takes FieldPats as input.
fn replace_fields_indexed(
&self,
new_pats: impl IntoIterator<Item = (usize, &'p Pat<'tcx>)>
) -> Self
fn replace_fields_indexed(
&self,
new_pats: impl IntoIterator<Item = (usize, &'p Pat<'tcx>)>
) -> Self
Overrides some of the fields with the provided patterns. This is used when a pattern
defines some fields but not all, for example Foo { field1: Some(_), .. }: here we start
with a Fields that is just one wildcard per field of the Foo struct, and override the
entry corresponding to field1 with the pattern Some(_). This is also used for slice
patterns for the same reason.
pub(super) fn replace_fields(
&self,
cx: &MatchCheckCtxt<'p, 'tcx>,
pats: impl IntoIterator<Item = Pat<'tcx>>
) -> Self
pub(super) fn replace_fields(
&self,
cx: &MatchCheckCtxt<'p, 'tcx>,
pats: impl IntoIterator<Item = Pat<'tcx>>
) -> Self
Replaces contained fields with the given list of patterns. There must be len() patterns
in pats.
Replaces contained fields with the arguments of the given pattern. Only use on a pattern
that is compatible with the constructor used to build self.
This is meant to be used on the result of Fields::wildcards(). The idea is that
wildcards constructs a list of fields where all entries are wildcards, and the pattern
provided to this function fills some of the fields with non-wildcards.
In the following example Fields::wildcards would return [_, _, _, _]. If we call
replace_with_pattern_arguments on it with the pattern, the result will be [Some(0), _, _, _].
let x: [Option<u8>; 4] = foo(); match x { [Some(0), ..] => {} }
This is guaranteed to preserve the number of patterns in self.
Trait Implementations
Auto Trait Implementations
impl<'p, 'tcx> !RefUnwindSafe for Fields<'p, 'tcx>
impl<'p, 'tcx> !UnwindSafe for Fields<'p, 'tcx>
Blanket Implementations
Mutably borrows from an owned value. Read more
Layout
Note: Most layout information is completely unstable and may be different between compiler versions and platforms. 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: 40 bytes