pub struct PatternColumn<'p, Cx: PatCx> { /* private fields */ }
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.
Implementations§
Source§impl<'p, Cx: PatCx> PatternColumn<'p, Cx>
impl<'p, Cx: PatCx> PatternColumn<'p, Cx>
pub fn new(arms: &[MatchArm<'p, Cx>]) -> Self
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.