Struct rustc_pattern_analysis::pat::DeconstructedPat
source · pub struct DeconstructedPat<'p, Cx: TypeCx> {
ctor: Constructor<Cx>,
fields: &'p [DeconstructedPat<'p, Cx>],
ty: Cx::Ty,
data: Cx::PatData,
useful: Cell<bool>,
}Expand description
Values and patterns can be represented as a constructor applied to some fields. This represents
a pattern in this form.
This also uses interior mutability to keep track of whether the pattern has been found reachable
during analysis. For this reason they cannot be cloned.
A DeconstructedPat will almost always come from user input; the only exception are some
Wildcards introduced during specialization.
Note that the number of fields 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. Care must
be taken when converting to/from thir::Pat.
Fields§
§ctor: Constructor<Cx>§fields: &'p [DeconstructedPat<'p, Cx>]§ty: Cx::Ty§data: Cx::PatData§useful: Cell<bool>Whether removing this arm would change the behavior of the match expression.
Implementations§
source§impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx>
impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx>
pub fn wildcard(ty: Cx::Ty, data: Cx::PatData) -> Self
pub fn new( ctor: Constructor<Cx>, fields: &'p [DeconstructedPat<'p, Cx>], ty: Cx::Ty, data: Cx::PatData ) -> Self
pub(crate) fn is_or_pat(&self) -> bool
sourcepub(crate) fn flatten_or_pat(&self) -> SmallVec<[&Self; 1]>
pub(crate) fn flatten_or_pat(&self) -> SmallVec<[&Self; 1]>
Expand this (possibly-nested) or-pattern into its alternatives.
pub fn ctor(&self) -> &Constructor<Cx>
pub fn ty(&self) -> Cx::Ty
pub fn data(&self) -> &Cx::PatData
pub fn iter_fields<'a>( &'a self ) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'a>
sourcepub(crate) fn specialize<'a>(
&self,
pcx: &PlaceCtxt<'a, 'p, Cx>,
other_ctor: &Constructor<Cx>
) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]>
pub(crate) fn specialize<'a>( &self, pcx: &PlaceCtxt<'a, 'p, Cx>, other_ctor: &Constructor<Cx> ) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]>
Specialize this pattern with a constructor.
other_ctor can be different from self.ctor, but must be covered by it.
sourcepub(crate) fn set_useful(&self)
pub(crate) fn set_useful(&self)
We keep track for each pattern if it was ever useful during the analysis. This is used with
redundant_subpatterns to report redundant subpatterns arising from or patterns.
pub(crate) fn is_useful(&self) -> bool
sourcepub(crate) fn redundant_subpatterns(&self) -> Vec<&Self>
pub(crate) fn redundant_subpatterns(&self) -> Vec<&Self>
Report the subpatterns that were not useful, if any.
fn collect_redundant_subpatterns<'a>(&'a self, subpats: &mut Vec<&'a Self>)
Trait Implementations§
Auto Trait Implementations§
impl<'p, Cx> !RefUnwindSafe for DeconstructedPat<'p, Cx>
impl<'p, Cx> !Send for DeconstructedPat<'p, Cx>
impl<'p, Cx> !Sync for DeconstructedPat<'p, Cx>
impl<'p, Cx> Unpin for DeconstructedPat<'p, Cx>
impl<'p, Cx> !UnwindSafe for DeconstructedPat<'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.