Struct rustc_pattern_analysis::usefulness::Matrix
source · struct Matrix<'a, 'p, Cx: TypeCx> {
rows: Vec<MatrixRow<'a, 'p, Cx>>,
wildcard_row: PatStack<'a, 'p, Cx>,
place_validity: SmallVec<[ValidityConstraint; 2]>,
}Expand description
A 2D matrix. Represents a list of pattern-tuples under investigation.
Invariant: each row must have the same length, and each column must have the same type.
Invariant: the first column must not contain or-patterns. This is handled by
Matrix::expand_and_push.
In fact each column corresponds to a place inside the scrutinee of the match. E.g. after
specializing (,) and Some on a pattern of type (Option<u32>, bool), the first column of
the matrix will correspond to scrutinee.0.Some.0 and the second column to scrutinee.1.
Fields§
§rows: Vec<MatrixRow<'a, 'p, Cx>>Vector of rows. The rows must form a rectangular 2D array. Moreover, all the patterns of each column must have the same type. Each column corresponds to a place within the scrutinee.
wildcard_row: PatStack<'a, 'p, Cx>Stores an extra fictitious row full of wildcards. Mostly used to keep track of the type of each column. This must obey the same invariants as the real rows.
place_validity: SmallVec<[ValidityConstraint; 2]>Track for each column/place whether it contains a known valid value.
Implementations§
source§impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx>
impl<'a, 'p, Cx: TypeCx> Matrix<'a, 'p, Cx>
sourcefn expand_and_push(&mut self, row: MatrixRow<'a, 'p, Cx>)
fn expand_and_push(&mut self, row: MatrixRow<'a, 'p, Cx>)
Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively
expands it. Internal method, prefer Matrix::new.
sourcefn new(
wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
arms: &'a [MatchArm<'p, Cx>],
scrut_ty: Cx::Ty,
scrut_validity: ValidityConstraint
) -> Self
fn new( wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>, arms: &'a [MatchArm<'p, Cx>], scrut_ty: Cx::Ty, scrut_validity: ValidityConstraint ) -> Self
Build a new matrix from an iterator of MatchArms.
fn head_ty(&self) -> Option<Cx::Ty>
fn column_count(&self) -> usize
fn rows<'b>( &'b self ) -> impl Iterator<Item = &'b MatrixRow<'a, 'p, Cx>> + Clone + DoubleEndedIterator + ExactSizeIterator
fn rows_mut<'b>( &'b mut self ) -> impl Iterator<Item = &'b mut MatrixRow<'a, 'p, Cx>> + DoubleEndedIterator + ExactSizeIterator
sourcefn heads<'b>(
&'b self
) -> impl Iterator<Item = &'b DeconstructedPat<'p, Cx>> + Clone + Captures<'a>
fn heads<'b>( &'b self ) -> impl Iterator<Item = &'b DeconstructedPat<'p, Cx>> + Clone + Captures<'a>
Iterate over the first pattern of each row.
sourcefn specialize_constructor(
&self,
pcx: &PlaceCtxt<'a, 'p, Cx>,
ctor: &Constructor<Cx>
) -> Matrix<'a, 'p, Cx>
fn specialize_constructor( &self, pcx: &PlaceCtxt<'a, 'p, Cx>, ctor: &Constructor<Cx> ) -> Matrix<'a, 'p, Cx>
This computes specialize(ctor, self). See top of the file for explanations.
Trait Implementations§
Auto Trait Implementations§
impl<'a, 'p, Cx> !RefUnwindSafe for Matrix<'a, 'p, Cx>
impl<'a, 'p, Cx> !Send for Matrix<'a, 'p, Cx>
impl<'a, 'p, Cx> !Sync for Matrix<'a, 'p, Cx>
impl<'a, 'p, Cx> Unpin for Matrix<'a, 'p, Cx>
impl<'a, 'p, Cx> !UnwindSafe for Matrix<'a, 'p, Cx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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: 72 bytes