Struct rustc_pattern_analysis::usefulness::Matrix
source · struct Matrix<'p, Cx: TypeCx> {
rows: Vec<MatrixRow<'p, Cx>>,
place_ty: SmallVec<[Cx::Ty; 2]>,
place_validity: SmallVec<[ValidityConstraint; 2]>,
wildcard_row_is_relevant: bool,
}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<'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.
place_ty: SmallVec<[Cx::Ty; 2]>Track the type of each column/place.
place_validity: SmallVec<[ValidityConstraint; 2]>Track for each column/place whether it contains a known valid value.
wildcard_row_is_relevant: boolTrack whether the virtual wildcard row used to compute exhaustiveness is relevant. See top of the file for details on relevancy.
Implementations§
source§impl<'p, Cx: TypeCx> Matrix<'p, Cx>
impl<'p, Cx: TypeCx> Matrix<'p, Cx>
sourcefn expand_and_push(&mut self, row: MatrixRow<'p, Cx>)
fn expand_and_push(&mut self, row: MatrixRow<'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(
arms: &[MatchArm<'p, Cx>],
scrut_ty: Cx::Ty,
scrut_validity: ValidityConstraint
) -> Self
fn new( arms: &[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( &self ) -> impl Iterator<Item = &MatrixRow<'p, Cx>> + Clone + DoubleEndedIterator + ExactSizeIterator
fn rows_mut( &mut self ) -> impl Iterator<Item = &mut MatrixRow<'p, Cx>> + DoubleEndedIterator + ExactSizeIterator
sourcefn heads(
&self
) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + Captures<'_>
fn heads( &self ) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + Captures<'_>
Iterate over the first pattern of each row.
sourcefn specialize_constructor(
&self,
pcx: &PlaceCtxt<'_, 'p, Cx>,
ctor: &Constructor<Cx>,
ctor_is_relevant: bool
) -> Matrix<'p, Cx>
fn specialize_constructor( &self, pcx: &PlaceCtxt<'_, 'p, Cx>, ctor: &Constructor<Cx>, ctor_is_relevant: bool ) -> Matrix<'p, Cx>
This computes specialize(ctor, self). See top of the file for explanations.
Trait Implementations§
Auto Trait Implementations§
impl<'p, Cx> !RefUnwindSafe for Matrix<'p, Cx>
impl<'p, Cx> !Send for Matrix<'p, Cx>
impl<'p, Cx> !Sync for Matrix<'p, Cx>
impl<'p, Cx> Unpin for Matrix<'p, Cx>
impl<'p, Cx> !UnwindSafe for Matrix<'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: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.