pub struct DeconstructedPat<'p, Cx: TypeCx> {
    ctor: Constructor<Cx>,
    fields: &'p [DeconstructedPat<'p, 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: &'p [DeconstructedPat<'p, 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<'p, Cx: TypeCx> DeconstructedPat<'p, Cx>

source

pub fn wildcard(ty: Cx::Ty) -> Self

source

pub fn new( ctor: Constructor<Cx>, fields: &'p [DeconstructedPat<'p, Cx>], ty: Cx::Ty, data: Cx::PatData ) -> Self

source

pub(crate) fn is_or_pat(&self) -> bool

source

pub fn ctor(&self) -> &Constructor<Cx>

source

pub fn ty(&self) -> Cx::Ty

source

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.

source

pub fn iter_fields( &self ) -> impl Iterator<Item = &'p DeconstructedPat<'p, Cx>> + Captures<'_>

source

pub(crate) fn specialize( &self, other_ctor: &Constructor<Cx>, ctor_arity: usize ) -> SmallVec<[PatOrWild<'p, Cx>; 2]>

Specialize this pattern with a constructor. other_ctor can be different from self.ctor, but must be covered by it.

source

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.

source

pub(crate) fn is_useful(&self) -> bool

source

pub(crate) fn redundant_subpatterns(&self) -> Vec<&Self>

Report the subpatterns that were not useful, if any.

source

fn collect_redundant_subpatterns<'a>(&'a self, subpats: &mut Vec<&'a Self>)

Trait Implementations§

source§

impl<'p, Cx: TypeCx> Debug for DeconstructedPat<'p, Cx>

This is best effort and not good enough for a Display impl.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where <Cx as TypeCx>::PatData: Unpin, <Cx as TypeCx>::StrLit: Unpin, <Cx as TypeCx>::Ty: Unpin, <Cx as TypeCx>::VariantIdx: Unpin,

§

impl<'p, Cx> !UnwindSafe for DeconstructedPat<'p, Cx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<'a, T> Captures<'a> for T
where 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.