Struct rustc_mir_build::thir::pattern::deconstruct_pat::Fields
source · pub(super) struct Fields<'p, 'tcx> {
fields: &'p [DeconstructedPat<'p, 'tcx>],
}
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 for a constructor using Fields::wildcards()
. The idea is that
Fields::wildcards()
constructs a list of fields where all entries are wildcards, and then
given a pattern we fill some of the fields with its subpatterns.
In the following example Fields::wildcards
returns [_, _, _, _]
. Then in
extract_pattern_arguments
we fill some of the entries, and the result is
[Some(0), _, _, _]
.
let x: [Option<u8>; 4] = foo();
match x {
[Some(0), ..] => {}
}
Note that the number of fields of a constructor may not match the fields declared in the
original struct/variant. This happens if a private or non_exhaustive
field is uninhabited,
because the code mustn’t observe that it is uninhabited. In that case that field is not
included in fields
. For that reason, when you have a mir::Field
you must use
index_with_declared_idx
.
Fields§
§fields: &'p [DeconstructedPat<'p, 'tcx>]
Implementations§
source§impl<'p, 'tcx> Fields<'p, 'tcx>
impl<'p, 'tcx> Fields<'p, 'tcx>
fn empty() -> Self
fn singleton(
cx: &MatchCheckCtxt<'p, 'tcx>,
field: DeconstructedPat<'p, 'tcx>
) -> Self
pub(super) fn from_iter(
cx: &MatchCheckCtxt<'p, 'tcx>,
fields: impl IntoIterator<Item = DeconstructedPat<'p, 'tcx>>
) -> Self
fn wildcards_from_tys(
cx: &MatchCheckCtxt<'p, 'tcx>,
tys: impl IntoIterator<Item = Ty<'tcx>>
) -> Self
sourcepub(super) fn wildcards(
pcx: &PatCtxt<'_, 'p, 'tcx>,
constructor: &Constructor<'tcx>
) -> Self
pub(super) fn wildcards(
pcx: &PatCtxt<'_, 'p, 'tcx>,
constructor: &Constructor<'tcx>
) -> Self
Creates a new list of wildcard fields for a given constructor. The result must have a
length of constructor.arity()
.
sourcepub(super) fn iter_patterns<'a>(
&'a self
) -> impl Iterator<Item = &'p DeconstructedPat<'p, 'tcx>> + Captures<'a>
pub(super) fn iter_patterns<'a>(
&'a self
) -> impl Iterator<Item = &'p DeconstructedPat<'p, 'tcx>> + Captures<'a>
Returns the list of patterns.
Trait Implementations§
impl<'p, 'tcx> Copy for Fields<'p, 'tcx>
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,
impl<'p, 'tcx> !UnwindSafe for Fields<'p, 'tcx>
Blanket Implementations§
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: 16 bytes