Struct rustc_pattern_analysis::pat_column::PatternColumn
source · pub struct PatternColumn<'p, Cx: TypeCx> {
patterns: Vec<&'p DeconstructedPat<Cx>>,
}Expand description
A column of patterns in a match, where a column is the intuitive notion of “subpatterns that
inspect the same subvalue/place”.
This is used to traverse patterns column-by-column for lints. Despite similarities with the
algorithm in crate::usefulness, this does a different traversal. Notably this is linear in
the depth of patterns, whereas compute_exhaustiveness_and_usefulness is worst-case exponential
(exhaustiveness is NP-complete). The core difference is that we treat sub-columns separately.
This is not used in the usefulness algorithm; only in lints.
Fields§
§patterns: Vec<&'p DeconstructedPat<Cx>>This must not contain an or-pattern. expand_and_push takes care to expand them.
Implementations§
source§impl<'p, Cx: TypeCx> PatternColumn<'p, Cx>
impl<'p, Cx: TypeCx> PatternColumn<'p, Cx>
pub fn new(arms: &[MatchArm<'p, Cx>]) -> Self
sourcefn expand_and_push(&mut self, pat: PatOrWild<'p, Cx>)
fn expand_and_push(&mut self, pat: PatOrWild<'p, Cx>)
Pushes a pattern onto the column, expanding any or-patterns into its subpatterns.
Internal method, prefer PatternColumn::new.
pub fn head_ty(&self) -> Option<&Cx::Ty>
pub fn iter<'a>( &'a self ) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> + Captures<'a>
sourcepub fn analyze_ctors(
&self,
cx: &Cx,
ty: &Cx::Ty
) -> Result<SplitConstructorSet<Cx>, Cx::Error>
pub fn analyze_ctors( &self, cx: &Cx, ty: &Cx::Ty ) -> Result<SplitConstructorSet<Cx>, Cx::Error>
Do constructor splitting on the constructors of the column.
sourcepub fn specialize(
&self,
cx: &Cx,
ty: &Cx::Ty,
ctor: &Constructor<Cx>
) -> Vec<PatternColumn<'p, Cx>>
pub fn specialize( &self, cx: &Cx, ty: &Cx::Ty, ctor: &Constructor<Cx> ) -> Vec<PatternColumn<'p, Cx>>
Does specialization: given a constructor, this takes the patterns from the column that match
the constructor, and outputs their fields.
This returns one column per field of the constructor. They usually all have the same length
(the number of patterns in self that matched ctor), except that we expand or-patterns
which may change the lengths.
Trait Implementations§
Auto Trait Implementations§
impl<'p, Cx> !RefUnwindSafe for PatternColumn<'p, Cx>
impl<'p, Cx> !Send for PatternColumn<'p, Cx>
impl<'p, Cx> !Sync for PatternColumn<'p, Cx>
impl<'p, Cx> Unpin for PatternColumn<'p, Cx>
impl<'p, Cx> !UnwindSafe for PatternColumn<'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: 24 bytes