pub trait PatCx: Sized + Debug {
type Ty: Clone + Debug;
type Error: Debug;
type VariantIdx: Clone + Idx + Debug;
type StrLit: Clone + PartialEq + Debug;
type ArmData: Copy + Clone + Debug;
type PatData: Clone;
// Required methods
fn is_exhaustive_patterns_feature_on(&self) -> bool;
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
fn ctor_sub_tys(
&self,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator;
fn ctors_for_ty(
&self,
ty: &Self::Ty,
) -> Result<ConstructorSet<Self>, Self::Error>;
fn write_variant_name(
f: &mut Formatter<'_>,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> Result;
fn bug(&self, fmt: Arguments<'_>) -> Self::Error;
fn complexity_exceeded(&self) -> Result<(), Self::Error>;
fn report_mixed_deref_pat_ctors(
&self,
deref_pat: &DeconstructedPat<Self>,
normal_pat: &DeconstructedPat<Self>,
) -> Self::Error;
// Provided methods
fn exhaustive_witnesses(&self) -> bool { ... }
fn lint_overlapping_range_endpoints(
&self,
_pat: &DeconstructedPat<Self>,
_overlaps_on: IntRange,
_overlaps_with: &[&DeconstructedPat<Self>],
) { ... }
fn lint_non_contiguous_range_endpoints(
&self,
_pat: &DeconstructedPat<Self>,
_gap: IntRange,
_gapped_with: &[&DeconstructedPat<Self>],
) { ... }
fn match_may_contain_deref_pats(&self) -> bool { ... }
}
Expand description
Context that provides type information about constructors.
Most of the crate is parameterized on a type that implements this trait.
Required Associated Types§
Sourcetype VariantIdx: Clone + Idx + Debug
type VariantIdx: Clone + Idx + Debug
The index of an enum variant.
Required Methods§
fn is_exhaustive_patterns_feature_on(&self) -> bool
Sourcefn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize
The number of fields for this constructor.
Sourcefn ctor_sub_tys(
&self,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator
fn ctor_sub_tys( &self, ctor: &Constructor<Self>, ty: &Self::Ty, ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator
The types of the fields for this constructor. The result must contain ctor_arity()
fields.
Sourcefn ctors_for_ty(
&self,
ty: &Self::Ty,
) -> Result<ConstructorSet<Self>, Self::Error>
fn ctors_for_ty( &self, ty: &Self::Ty, ) -> Result<ConstructorSet<Self>, Self::Error>
The set of all the constructors for ty
.
This must follow the invariants of ConstructorSet
Sourcefn write_variant_name(
f: &mut Formatter<'_>,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> Result
fn write_variant_name( f: &mut Formatter<'_>, ctor: &Constructor<Self>, ty: &Self::Ty, ) -> Result
Write the name of the variant represented by pat
. Used for the best-effort Debug
impl of
DeconstructedPat
. Only invoqued when pat.ctor()
is Struct | Variant(_) | UnionField
.
Sourcefn complexity_exceeded(&self) -> Result<(), Self::Error>
fn complexity_exceeded(&self) -> Result<(), Self::Error>
The maximum pattern complexity limit was reached.
Sourcefn report_mixed_deref_pat_ctors(
&self,
deref_pat: &DeconstructedPat<Self>,
normal_pat: &DeconstructedPat<Self>,
) -> Self::Error
fn report_mixed_deref_pat_ctors( &self, deref_pat: &DeconstructedPat<Self>, normal_pat: &DeconstructedPat<Self>, ) -> Self::Error
The current implementation of deref patterns requires that they can’t match on the same
place as a normal constructor. Since this isn’t caught by type-checking, we check it in the
PatCx
before running the analysis. This reports an error if the check fails.
Provided Methods§
Sourcefn exhaustive_witnesses(&self) -> bool
fn exhaustive_witnesses(&self) -> bool
Whether to ensure the non-exhaustiveness witnesses we report for a complete set. This is
false
by default to avoid some exponential blowup cases such as
https://github.com/rust-lang/rust/issues/118437.
Sourcefn lint_overlapping_range_endpoints(
&self,
_pat: &DeconstructedPat<Self>,
_overlaps_on: IntRange,
_overlaps_with: &[&DeconstructedPat<Self>],
)
fn lint_overlapping_range_endpoints( &self, _pat: &DeconstructedPat<Self>, _overlaps_on: IntRange, _overlaps_with: &[&DeconstructedPat<Self>], )
Lint that the range pat
overlapped with all the ranges in overlaps_with
, where the range
they overlapped over is overlaps_on
. We only detect singleton overlaps.
The default implementation does nothing.
Sourcefn lint_non_contiguous_range_endpoints(
&self,
_pat: &DeconstructedPat<Self>,
_gap: IntRange,
_gapped_with: &[&DeconstructedPat<Self>],
)
fn lint_non_contiguous_range_endpoints( &self, _pat: &DeconstructedPat<Self>, _gap: IntRange, _gapped_with: &[&DeconstructedPat<Self>], )
Lint that there is a gap gap
between pat
and all of gapped_with
such that the gap is
not matched by another range. If gapped_with
is empty, then gap
is T::MAX
. We only
detect singleton gaps.
The default implementation does nothing.
Sourcefn match_may_contain_deref_pats(&self) -> bool
fn match_may_contain_deref_pats(&self) -> bool
Check if we may need to perform additional deref-pattern-specific validation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.