[−][src]Enum rustc_mir_build::thir::pattern::_match::Fields
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.
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 subtle because we
still need to have those fields back when going to/from a Pat. Most of this is handled
automatically in Fields, but when constructing or deconstructing Fields you need to be
careful. As a rule, when going to/from the matrix, use the filtered field list; when going
to/from Pat, use the full field list.
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. kept_count caches the number of
non-hidden fields.
Fields of Filtered
fields: SmallVec<[FilteredField<'p, 'tcx>; 2]>kept_count: usizeImplementations
impl<'p, 'tcx> Fields<'p, 'tcx>[src]
fn empty() -> Self[src]
fn from_single_pattern(pat: &'p Pat<'tcx>) -> Self[src]
Construct a new Fields from the given pattern. Must not be used if the pattern is a field
of a struct/tuple/variant.
fn from_slice_unfiltered(pats: &'p [Pat<'tcx>]) -> Self[src]
Construct a new Fields from the given patterns. You must be sure those patterns can't
contain fields that need to be filtered out. When in doubt, prefer replace_fields.
fn wildcards_from_tys(
cx: &MatchCheckCtxt<'p, 'tcx>,
tys: impl IntoIterator<Item = Ty<'tcx>>
) -> Self[src]
cx: &MatchCheckCtxt<'p, 'tcx>,
tys: impl IntoIterator<Item = Ty<'tcx>>
) -> Self
Convenience; internal use.
fn wildcards(
cx: &MatchCheckCtxt<'p, 'tcx>,
constructor: &Constructor<'tcx>,
ty: Ty<'tcx>
) -> Self[src]
cx: &MatchCheckCtxt<'p, 'tcx>,
constructor: &Constructor<'tcx>,
ty: Ty<'tcx>
) -> Self
Creates a new list of wildcard fields for a given constructor.
fn len(&self) -> usize[src]
Returns the number of patterns from the viewpoint of match-checking, i.e. excluding hidden
fields. This is what we want in most cases in this file, the only exception being
conversion to/from Pat.
fn all_patterns(self) -> impl Iterator<Item = Pat<'tcx>>[src]
Returns the complete list of patterns, including hidden fields.
fn replace_with_fieldpats(
&self,
new_pats: impl IntoIterator<Item = &'p FieldPat<'tcx>>
) -> Self[src]
&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[src]
&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.
fn replace_fields(
&self,
cx: &MatchCheckCtxt<'p, 'tcx>,
pats: impl IntoIterator<Item = Pat<'tcx>>
) -> Self[src]
&self,
cx: &MatchCheckCtxt<'p, 'tcx>,
pats: impl IntoIterator<Item = Pat<'tcx>>
) -> Self
Replaces contained fields with the given filtered list of patterns, e.g. taken from the
matrix. There must be len() patterns in pats.
fn push_on_patstack(self, stack: &[&'p Pat<'tcx>]) -> PatStack<'p, 'tcx>[src]
Trait Implementations
Auto Trait Implementations
impl<'p, 'tcx> !RefUnwindSafe for Fields<'p, 'tcx>
impl<'p, 'tcx> !Send for Fields<'p, 'tcx>
impl<'p, 'tcx> !Sync for Fields<'p, 'tcx>
impl<'p, 'tcx> Unpin for Fields<'p, 'tcx> where
'tcx: 'p,
'tcx: 'p,
impl<'p, 'tcx> !UnwindSafe for Fields<'p, 'tcx>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,