Struct rustc_pattern_analysis::pat::DeconstructedPat
source · pub struct DeconstructedPat<Cx: TypeCx> {
ctor: Constructor<Cx>,
fields: Vec<DeconstructedPat<Cx>>,
ty: Cx::Ty,
data: Option<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: Vec<DeconstructedPat<Cx>>§ty: Cx::Ty§data: Option<Cx::PatData>Extra data to store in a pattern. None if the pattern is a wildcard that does not
correspond to a user-supplied pattern.
useful: Cell<bool>Whether removing this arm would change the behavior of the match expression.
Implementations§
source§impl<Cx: TypeCx> DeconstructedPat<Cx>
impl<Cx: TypeCx> DeconstructedPat<Cx>
pub fn wildcard(ty: Cx::Ty) -> Self
pub fn new( ctor: Constructor<Cx>, fields: Vec<DeconstructedPat<Cx>>, ty: Cx::Ty, data: Cx::PatData ) -> Self
pub(crate) fn is_or_pat(&self) -> bool
pub fn ctor(&self) -> &Constructor<Cx>
pub fn ty(&self) -> &Cx::Ty
sourcepub fn data(&self) -> Option<&Cx::PatData>
pub fn data(&self) -> Option<&Cx::PatData>
Returns the extra data stored in a pattern. Returns None if the pattern is a wildcard that
does not correspond to a user-supplied pattern.
pub fn iter_fields<'a>( &'a self ) -> impl Iterator<Item = &'a DeconstructedPat<Cx>>
sourcepub(crate) fn specialize<'a>(
&'a self,
other_ctor: &Constructor<Cx>,
ctor_arity: usize
) -> SmallVec<[PatOrWild<'a, Cx>; 2]>
pub(crate) fn specialize<'a>( &'a self, other_ctor: &Constructor<Cx>, ctor_arity: usize ) -> SmallVec<[PatOrWild<'a, 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<Cx> !RefUnwindSafe for DeconstructedPat<Cx>
impl<Cx> Send for DeconstructedPat<Cx>
impl<Cx> !Sync for DeconstructedPat<Cx>
impl<Cx> Unpin for DeconstructedPat<Cx>
impl<Cx> UnwindSafe for DeconstructedPat<Cx>where
<Cx as TypeCx>::PatData: UnwindSafe,
<Cx as TypeCx>::StrLit: UnwindSafe,
<Cx as TypeCx>::Ty: UnwindSafe,
<Cx as TypeCx>::VariantIdx: UnwindSafe,
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.