Struct rustc_pattern_analysis::pat::DeconstructedPat
source · pub struct DeconstructedPat<'p, 'tcx> {
ctor: Constructor<'tcx>,
fields: &'p [DeconstructedPat<'p, 'tcx>],
ty: Ty<'tcx>,
span: Span,
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<'tcx>§fields: &'p [DeconstructedPat<'p, 'tcx>]§ty: Ty<'tcx>§span: Span§useful: Cell<bool>Whether removing this arm would change the behavior of the match expression.
Implementations§
source§impl<'p, 'tcx> DeconstructedPat<'p, 'tcx>
impl<'p, 'tcx> DeconstructedPat<'p, 'tcx>
pub fn wildcard(ty: Ty<'tcx>, span: Span) -> Self
pub fn new( ctor: Constructor<'tcx>, fields: &'p [DeconstructedPat<'p, 'tcx>], ty: Ty<'tcx>, span: Span ) -> Self
pub(crate) fn is_or_pat(&self) -> bool
sourcepub(crate) fn flatten_or_pat(&'p self) -> SmallVec<[&'p Self; 1]>
pub(crate) fn flatten_or_pat(&'p self) -> SmallVec<[&'p Self; 1]>
Expand this (possibly-nested) or-pattern into its alternatives.
pub fn ctor(&self) -> &Constructor<'tcx>
pub fn ty(&self) -> Ty<'tcx>
pub fn span(&self) -> Span
pub fn iter_fields<'a>( &'a self ) -> impl Iterator<Item = &'p DeconstructedPat<'p, 'tcx>> + Captures<'a>
sourcepub(crate) fn specialize<'a>(
&'a self,
pcx: &PatCtxt<'_, 'p, 'tcx>,
other_ctor: &Constructor<'tcx>
) -> SmallVec<[&'p DeconstructedPat<'p, 'tcx>; 2]>
pub(crate) fn specialize<'a>( &'a self, pcx: &PatCtxt<'_, 'p, 'tcx>, other_ctor: &Constructor<'tcx> ) -> SmallVec<[&'p DeconstructedPat<'p, 'tcx>; 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_spans to report redundant subpatterns arising from or patterns.
pub(crate) fn is_useful(&self) -> bool
sourcepub(crate) fn redundant_spans(&self) -> Vec<Span>
pub(crate) fn redundant_spans(&self) -> Vec<Span>
Report the spans of subpatterns that were not useful, if any.
fn collect_redundant_spans(&self, spans: &mut Vec<Span>)
Trait Implementations§
Auto Trait Implementations§
impl<'p, 'tcx> !RefUnwindSafe for DeconstructedPat<'p, 'tcx>
impl<'p, 'tcx> !Send for DeconstructedPat<'p, 'tcx>
impl<'p, 'tcx> !Sync for DeconstructedPat<'p, 'tcx>
impl<'p, 'tcx> Unpin for DeconstructedPat<'p, 'tcx>
impl<'p, 'tcx> !UnwindSafe for DeconstructedPat<'p, 'tcx>
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
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: 96 bytes